Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Bit mask

Reply
Thread Tools

Re: Bit mask

 
 
Eric Sosman
Guest
Posts: n/a
 
      01-07-2004
Als wrote:
>
> What's an efficient way to mask a last 3 bits of a 8-bit char and make them
> all zero?
>
> Bit-shifting is possible but not sure if it is efficient enough.
>
> Example:
>
> 01011[010] --> 01011[000]


Many or perhaps even most C implementations use an
eight-bit `char', but that is not actually guaranteed
by the language, and implementations using wider `char'
are known to exist. Still:

unsigned char byte = 0x5A; /* 00...01011010 */
byte &= ~ 0x07; /* AND with 11...11111000 */
/* result: 00...01011000 */

Also, the Standard says nothing about the relative
efficiency of operations in C. In fact, *you* haven't
said what you mean by "efficiency!" Do you want minimal
code size, minimal register usage, minimal execution
time, minimal debugging time ...?

--

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the point of having 16 bit colour if a computer monitor can only display 8 bit colour? How do you edit 16 bit colour when you can only see 8 bit? Scotius Digital Photography 6 07-13-2010 03:33 AM
Conversion mask in hex to bit mask Marcin Tyman Ruby 4 05-06-2008 08:15 PM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit, Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new ! vvcd Computer Support 0 09-17-2004 08:15 PM
[networking] Convert subnet mask <=> mask length 187 Perl Misc 2 07-29-2004 10:31 AM
64 bit - Windows Liberty 64bit, Windows Limited Edition 64 Bit,Microsoft SQL Server 2000 Developer Edition 64 Bit, IBM DB2 64 bit - new! Ionizer Computer Support 1 01-01-2004 07:27 PM



Advertisments