Please give me an idea how to show all the bits of a number using bitwise shift operator....and hence represent the number in 2's complement representation
Please give me an idea how to show all the bits of a number using bitwise shift operator....and hence represent the number in 2's complement representation
You can use bitwise-and like so to get the least significant bit:
You can then do a right-shift and repeat the process to get the next bit, and so on, until all bits have been extracted (you could save these in an array if you want?). It might also be a good idea to look at the sizeof() operator, if you want to know how many bytes/bits are in a given type.Code:int myNumber; int myBit = myNumber & 1;
How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.