c++ - Print the binary format of a char -


I wrote a function to print binary format months ago, this is how it And it worked well:

  zero prnCharbit (four x) {int i, mask; For (i = CHAR_BIT; i> = 1; i--) {mask = (1 <- (i-1)) and; Putchar ((mask == 0 '0': '1'); } Cursed ('\ n'); }  

And today I want to use this function so I wrote almost the same as a function on it:

  zero PrnCharBit (char c) { Int i; Four mask = 0; // printf ("% d \ n", CHAR_MAX); For (i = size (character) * CHAR_BIT-1; i> = 0; i--) {mask = 1 & lt; & Lt; I; If (Mask & C == 0) Tutor ('0'); And fever ('1'); } Cursed ('\ n'); }  

However, the second function does not work. I do not understand, because the two functions are almost identical! Why does the second task not produce the same results? Equality operator (

Before Operator Bitular Operation ( & amp; Code> == ).

The Clang gives this warning;

& amp; Less than == is preferred; == will be evaluated first

Change your second function to if (mask and C == 0) to if ((Mask & amp; C) = = 0)


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -