ビット文字列
ビット文字列とは、圧縮された一連のビットで構成される、もう 1 つの特殊な文字列です。32K の変数には、ほぼ 256K ビットが格納できます。ビット文字列の作成および作業用に、以下の特殊な関数が用意されています。
-
$Bit は、ビット (1 または 0) を取得するか、または (Set と共に使用した場合) ビットを 1 または 0 に設定します。下の例では、$Random(2) を使用して 1 または 0 をランダムに生成しています。
-
$BitCount はビットをカウントします。
-
$BitFind は、特定の値 (1 または 0) を持つ次のビットを検索します。
-
$BitLogic は、ビット文字列に対してビット演算 (and、or、not、xor) を実行します。
-
$Factor は、整数を対応するビット文字列に変換します。例えば、$Factor(4) はビット文字列 001 を返します。
ビット文字列は圧縮されているため、Write は使用しないでください。代わりに $Bit を使用するか、バイトおよびビット内容の両方を表示できる Zwrite コマンドを使用してください。
SAMPLES>for i=1:1:40 {set $bit(b, i) = $random(2)}
SAMPLES>write $bitcount(b, 0)
23
SAMPLES>write $bitcount(b, 1)
17
SAMPLES>for i = 1:1:40 {write $bit(b, i)}
0100110001000110101011001100010010000111
SAMPLES>write $bitfind(b, 1, 1) // find the first 1 bit
2
SAMPLES>write $bitfind(b, 0, 1) // find the first 0 bit
1
SAMPLES>write $bitfind(b, 1, 3) // find the next 1 bit
5
SAMPLES>for i = 1:1:40 {set $bit(c, i) = $random(2)}
SAMPLES>set d = $bitlogic(b & c)
SAMPLES>for i = 1:1:40 {write $bit(b, i)}
0100110001000110101011001100010010000111
SAMPLES>for i = 1:1:40 {write $bit(c, i)}
0111001111001011110100100110101110111011
SAMPLES>for i = 1:1:40 {write $bit(d, i)}
0100000001000010100000000100000010000011
SAMPLES>set f = $factor(23456)
SAMPLES>zwrite f // shows the bitstring representing 23456
f=$c(128,0,4,0)_" ["_$c(0,0)/*$bit(000001011101101)*/