c - Trouble with reversing the order -


I am trying to print the binary number in C, but I have the dilemma that its printing in the reverse order Its being done. I have defined a statement that tell me how many pieces are, in this way I can work back from the previous bit

I get the nth bit of

  I can use (Price & gt; & gt; Cooler of bits) & amp; 1;  

In some loops, I call it totalNumberOfBits == 0; Such as

  while (totalNumberOfBits! = 0) {putchar (n> columnmer of bits) & amp; 1; TotalNumberOfBits--; }  

Any hints will be given - I think that I can stop the mood, I have an attitude that prints the number right behind it, but iam to avoid this Trying to find a way

thanks

  while ( TotalNumberOfBits! = 0) {putchar (n & gt; total number of bits) & amp; 1; TotalNumberOfBits--; }  

OK, you were very close to code (and actually already printing bits in the correct order), however, there were 3 minor errors first, when the Visual Studio The compilation gives me the following warning:

  Warning C4552: '& amp; Operator has no effect; Expected operator with side effects  

this & amp; Complaining about; 1 is part of your code, which you think is mistakenly placed outside of your putchar code function.

  while (totalNumberOfBits! = 0) {cucumber ((n & gt; colonnumber of bits) & amp; 1); TotalNumberOfBits--; } The second error is that, when it is printing bits correctly, you are printing \ 0 and \ 1 characters. \ 0 will not show in the console, and \ 1 will probably look like a smiley, then fix it exactly like that.  
  while (totalNumberOfBits! = 0) {putchar (((n & gt; total number of bits) and 1) '1': '0'); TotalNumberOfBits--; }  

It is very close now, the remaining one small mistake is left. Because your loop displays, and in which place you decrease the totalNumberOfBits , you do not check the bit for 2 ^ 0, while you check 2 ^ 8, even if your < Code> n is only 8 bits (and thus out of range). So we move subtraction, and ! = :

  (--totalNumberOfBits> = 0) {putchar (((> nullough of bits)) and 1) '1': '0 '); }  

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -