I want to display my decimal number as bits.
int g = 2323;
for (int i = 31; i>=0; i--) // int has 32 bits
{
Console.Write(((g >> 1) & 1) == 1 ? "1" : "0"); // shift right 1 and display it
g = g / 2; // shift right= divide by 2
}
However this display the number like mirror ( 12345 -> 54321)
I could shift left from the left but then : I might get exception ..(too big number)
What should i need to change in my code to display it correct but :
- no convert(…) method
- no insertion to middleman array
- no recursion.
Is there anything ?
Just off the top of my head: