Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
02/07/06 19:41
Read: times


 
#109436 - Right Filling n x Rightmost Bits with 1'
Hi all

A question to draw on the experience of those here. The language is C, I would like to fill n x Bits on the righthand side of my 16 bit variable 'Mask'

with least amount of code possible for instance I have a variable 'Mask' that currently holds a value of

0101 0101 0101 0000

I want to fill the righthand 4 bits with 1's so the result is.

0101 0101 0101 1111

I am free to bit shift the Mask in any way in order to achieve this result.

Here is what I have currently.

25Bytes
Mask |= 2^RightMostBits -1;


33Bytes
Mask |= 0xFFFF>>(16-RightMostBits);


33Bytes
for i = 0; i<RightMostBits i++){
temp = 0x01 << i;
Mask |= temp;
}

Any other suggestions appreciated

Regards

Marshall

List of 16 messages in thread
TopicAuthorDate
Right Filling n x Rightmost Bits with 1'            01/01/70 00:00      
   wrong approach            01/01/70 00:00      
      Wrong Approach ?            01/01/70 00:00      
         why not just |= bits_to_be_added            01/01/70 00:00      
            |= bits_to_be_added            01/01/70 00:00      
               ah            01/01/70 00:00      
                  bang on            01/01/70 00:00      
   Try an Array            01/01/70 00:00      
   |= 2^RightMostBits -1; // sure?            01/01/70 00:00      
      You are correct about ^ != pow()            01/01/70 00:00      
      If only            01/01/70 00:00      
   About 25 bytes with SDCC            01/01/70 00:00      
      Thankyou            01/01/70 00:00      
      Why not use a table?            01/01/70 00:00      
         codesize            01/01/70 00:00      
            Yes, But..            01/01/70 00:00      

Back to Subject List