# Binary representation of a number, binary operators.

• 11-25-2006
apacz
Binary representation of a number, binary operators.
Hi,
I have to deal with a binary representation of a number, starting with most significant bit. The problem is that I don't have enough memory to keep the whole binary representation so I can't just simply convert the number in base 10 to it's binary representation. Is it possible to get every bit from some number starting from MSB (using binary operators) so I don't have to keep whole number's binary representation in memory ?
Regards.
• 11-25-2006
Mario F.
You mean you don't have enough memory to keep an array of 16, 32 or 64 booleans? (C99)

Anyways, one way you can do this, assuming the value can be antything from a char to a double, is to build a for loop of as many as steps as your number size in bits.

Then you shift left with the operator <<, taking the MSB. You calculate the mask from your position in the for loop.
• 11-25-2006
Dave_Sinkula
• 11-25-2006
apacz
Thank you for help.