1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

0と1を0と任意の値(たとえば、46)にして遊ぶ。

Last updated at Posted at 2025-05-12

いろいろ、注意

  • UNOでの予定は、未定
  • こんな、どうでも、いいので、ややヒット。
  • 用途しては、どうしても、高速化が必要なところ。

プログラム

オンラインコンパイラーPAIZA



//8ビット分、2進数に変換して表示するマクロ(注意!!!入力は、破壊される
#define bit8_put(aa) for(int ii=8;ii!=0;ii--){if(aa&0x80){printf("1");}else{printf("0");}aa=aa<<1;}

#include <iostream>
using namespace std;
int main(void){
    // Your code here!

    char a;

    a = 0;
    
    printf("IN[%d]\n",a);
    
    a  = (0 - a) & 46;
    
    printf("OUT[%d]\n",a);
    bit8_put(a);
    printf("\n\n");
    
    a = 1;
    
    printf("IN[%d]\n",a);

    a  = (0 - a) & 46;

    printf("OUT[%d]\n",a);
    
    bit8_put(a);
}



IN[0]
OUT[0]
00000000

IN[1]
OUT[46]
00101110


おまけ(掛け算でのやり方)





//8ビット分、2進数に変換して表示するマクロ(注意!!!入力は、破壊される
#define bit8_put(aa) for(int ii=8;ii!=0;ii--){if(aa&0x80){printf("1");}else{printf("0");}aa=aa<<1;}

#include <iostream>
using namespace std;
int main(void){
    // Your code here!

    char a;

    a = 0;
    
    printf("IN[%d]\n",a);
    
    a  = a * 46;
    
    printf("OUT[%d]\n",a);
    bit8_put(a);
    printf("\n\n");
    
    a = 1;
    
    printf("IN[%d]\n",a);

    a  = a * 46;

    printf("OUT[%d]\n",a);
    
    bit8_put(a);
}




IN[0]
OUT[0]
00000000

IN[1]
OUT[46]
00101110

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?