30 lines
679 B
Plaintext
30 lines
679 B
Plaintext
to format :str :width [pad (char 32)]
|
|
while [(count :str) < :width] [
|
|
make "str word :pad :str
|
|
]
|
|
output :str
|
|
end
|
|
|
|
; Output binary representation of a number
|
|
to binary :number [:width 1]
|
|
local "bits
|
|
ifelse [:number = 0] [
|
|
make "bits 0
|
|
] [
|
|
make "bits "
|
|
while [:number > 0] [
|
|
make "bits word (bitand :number 1) :bits
|
|
make "number lshift :number -1
|
|
]
|
|
]
|
|
output (format :bits :width 0)
|
|
end
|
|
|
|
repeat 32 [
|
|
make "num repcount - 1
|
|
make "gray gray_encode :num
|
|
make "decoded gray_decode :gray
|
|
print (sentence (format :num 2) ": (binary :num 5) ": (binary :gray 5) ":
|
|
(binary :decoded 5) ": (format :decoded 2)) ]
|
|
bye
|