how to output an int in binary?

后端 未结 5 1601
醉梦人生
醉梦人生 2020-12-09 17:41
int x = 5;
cout<<(char)x;

the code above outputs an int x in raw binary, but only 1 byte. what I need it to do is output the x as 4-bytes in

5条回答
  •  暖寄归人
    2020-12-09 18:45

    A couple of hints.

    First, to be between 0 and 2^32 - 1 you'll need an unsigned four-byte int.

    Second, the four bytes starting at the address of x (&x) already have the bytes you want.

    Does that help?

提交回复
热议问题