0
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?

(UNO)ビットサーチ 1ビットだけ立っているビットを探すらしい、遊びらいし

Posted at

目的
ビット列から1ビットを探す。

いろいろ
例題の中の例題らしい、基本中の基本らしい
いままで、ファミコンで遊んだりプログラムを書いたり
してきたが、存在は、知っていたが、初めてプログラムしてみた
いままで、1度もつかった事は、ない
だいたい、1の値しか示さないのにシフト操作なんかする?たぶんしない。
ビットの概念の勉強用

結果

o_coq312.jpg

プログラム



//bit_search_UNO_1
//ビットサーチ
//ビットの立った、1ビットを探す


//初期化
void setup() {

  Serial.begin(9600);
  Serial.println("START");

  //unsigned char a = 0b10000000;
  //unsigned char a = 0b01000000;
  unsigned char a = 0b00100000;
  //unsigned char a = 0b00010000;

  //unsigned char a = 0b00001000;
  //unsigned char a = 0b00000100;
  //unsigned char a = 0b00000010;
  //unsigned char a = 0b00000001;

  int b = 0;

  if ((a & 0b11110000) != 0) {
    Serial.println("11110000");//debug
    b = b + 4;
  }//endif

  if ((a & 0b11001100) != 0) {
    Serial.println("11001100");//debug
    b = b + 2;
  }//endif

  if ((a & 0b10101010) != 0) {
    Serial.println("10101010");//debug
    b = b + 1;
  }//endif

  Serial.println(b);

}//setup


//メインループ
void loop() {
}//loop


0
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
0
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?