LoginSignup
0
0

More than 5 years have passed since last update.

smallbasicでビット操作

Posted at

smallbasicは、ビット操作の演算子が無い。
0~255を使って、なんとかする。
以下は、2進数表示。

サンプルコード

a = 255
If a - 128 < 0 then
  TextWindow.Write(0)
Else
  TextWindow.Write(1)
  a = a - 128 
endif
If a - 64 < 0 then
  TextWindow.Write(0)
Else
  TextWindow.Write(1)
  a = a - 64 
endif
If a - 32 < 0 then
  TextWindow.Write(0)
Else
  TextWindow.Write(1)
  a = a - 32 
endif
If a - 16 < 0 then
  TextWindow.Write(0)
Else
  TextWindow.Write(1)
  a = a - 16
endif
If a - 8 < 0 then
   TextWindow.Write(0)
Else
   TextWindow.Write(1)
   a = a - 8 
endif
If a - 4 < 0 then
  TextWindow.Write(0)
Else
  TextWindow.Write(1)
  a = a - 4 
EndIf
If a - 2 < 0 then
  TextWindow.Write(0)
Else
  TextWindow.Write(1)
  a = a - 2 
EndIf 
TextWindow.Write(a)
TextWindow.WriteLine("")
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