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と11111111(-1)にして遊ぶ。(計算、加算器で)ビットマスクの為

Last updated at Posted at 2025-05-11

いろいろ、注意

  • UNOでの予定は、未定 (真面目にUNOでやっても、いいんだけど意味が無いから)
  • UNOは、C++言語である。(とうぜん8ビット機)
  • 0と1からビットマスクを使って任意の値にすると高速に処理できる?
  • 掛け算を使えは、なしということで(例題の趣旨に反する)(アキュムレーター(全加算器)を使って遊ぶ)(細かいつこみが入りそうだけどALUに繋がつているのは、アキュムレーター(レジスター(加算器)))

プログラム

オンラインコンパイラー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;
    char b;
    
    a = 0;
    
    printf("IN[%d]\n",a);
    
    b = 0 - a;
    
    printf("OUT[%d]\n",b);
    printf("\n");
    
    a = 1;
    
    printf("IN[%d]\n",a);
    
    b = 0 - a;

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



IN[0]
OUT[0]

IN[1]
OUT[-1]
11111111

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?