Skip to main content

This documentation is for an older version of this product. See the latest version of this content.Opens in a new tab

ビット文字列

ビット文字列とは、圧縮された一連のビットで構成される、もう 1 つの特殊な文字列です。32K の変数には、ほぼ 256K ビットが格納できます。ビット文字列の作成および作業用に、以下の特殊な関数が用意されています。

  • $Bit は、ビット (1 または 0) を取得するか、または (Set と共に使用した場合) ビットを 1 または 0 に設定します。下の例では、$Random(2) を使用して 1 または 0 をランダムに生成しています。

  • $BitCount はビットをカウントします。

  • $BitFind は、特定の値 (1 または 0) を持つ次のビットを検索します。

  • $BitLogic は、ビット文字列に対してビット演算 (and、or、not、xor) を実行します。

  • $Factor は、整数を対応するビット文字列に変換します。例えば、$Factor(20) は、ビット文字列 00101 を返します (位置の値が 4 および 16 であるビットが設定されている場合のみ)。

ビット文字列は圧縮されているため、Write は使用しないでください。代わりに $Bit を使用するか、バイトおよびビット内容の両方を表示できる ZWrite コマンドを使用してください。

ターミナル


USER>for i = 1:1:40 {set $bit(b, i) = $random(2)}

USER>write $bitcount(b, 0)
23
USER>write $bitcount(b, 1)
17
USER>for i = 1:1:40 {write $bit(b, i)}
0100110001000110101011001100010010000111
USER>write $bitfind(b, 1, 1) // find the first 1 bit, starting at position 1
2
USER>write $bitfind(b, 0, 1) // find the first 0 bit, starting at position 1
1
USER>write $bitfind(b, 1, 3) // find the next 1 bit, starting at position 3
5
USER>for i = 1:1:40 {set $bit(c, i) = $random(2)}

USER>set d = $bitlogic(b & c)

USER>for i = 1:1:40 {write $bit(b, i)}
0100110001000110101011001100010010000111
USER>for i = 1:1:40 {write $bit(c, i)}
0111001111001011110100100110101110111011
USER>for i = 1:1:40 {write $bit(d, i)}
0100000001000010100000000100000010000011
USER>set f = $factor(3456)

USER>zwrite f  // shows the bits representing 3456
f=$zwc(128,4)_$c(128,13,0,0)/*$bit(8,9,11,12)*/
USER>set sum = 0 write !, sum for i=8,9,11,12 { set sum = sum + (2 ** (i-1)) write " + 2**", (i-1) } write " = ", sum 

0 + 2**7 + 2**8 + 2**10 + 2**11 = 3456
USER>

利用可能なツール

ビット文字列に変換する次のメソッドを提供します。

  • StringToBit()

  • ZBitToBit()

可用性 : 全ネームスペース。

FeedbackOpens in a new tab