how to output an int in binary?

后端 未结 5 1625
醉梦人生
醉梦人生 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:34

    and what about this?

    int x = 5;
    cout<<(char) ((0xff000000 & x) >> 24);
    cout<<(char) ((0x00ff0000 & x) >> 16);
    cout<<(char) ((0x0000ff00 & x) >> 8);
    cout<<(char) (0x000000ff & x);
    

提交回复
热议问题