べつにたいした手間ではないですが、書かされるという気分が知性に対する挑戦のように思えるわけですね。
こんなことをやらされるために頭脳があるんじゃない!みたいな。
もしそんな教師がいたら最悪ですね。でも現実は頭脳に厳しい。
というわけで書きました。
なんか頭にくるのでここに載せときます。
注意点として、(int16_t)0xff などとキャストすると結果は 1111111111111111 と表示されます。
当然そうなるわけなんですが、0000000011111111 とはなりません。
注意しましょう。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int8_t x=0b010101; | |
for(int i=7;0<=i;i--) | |
{ | |
cout << ((x>>i)&1); | |
} | |
cout << endl; | |
return 0; | |
} |