top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

C Program for setting of bits in one byte from 7 to 4 bits with 5 without changing remaing values

+5 votes
637 views
C Program for setting of bits in one byte from 7 to 4 bits with 5 without changing remaing values
posted Dec 30, 2013 by Giri Prasad

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

Say your input is integer a (4 bytes) and you want set the bits from 4 to 7 then you need to do bitwise OR with a number which has 1 at those bits and 0 as remaining bits;

a = a | 0x00000074 
// 0x74 is 01111000 in binary.
answer Dec 30, 2013 by Luv Kumar
0 votes

//C Program for setting of bits in one byte from 7 to 4 bits with 5 without changing remaing values
num=num|1<<4;
num=num&~(1<<5);
num=num|1<<6;
num=num&~(1<<7);
printf("%d",num);

answer Dec 27, 2015 by Rajan Paswan
Similar Questions
+6 votes

Say you are given "Hello World"
Output should be "olleH dlroW"

+4 votes

How to swap ith and jth Bits for a 32-Bit Integer?

+4 votes
                                      *
                                     * *
                                    * * *
                                   * * * *
                                  * * * * * 
                                 * * * *     

I above Ouput I Missed two stars.My question is how to find out the remaining stars.Please tel me in the C programming way.

...