Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Gray-code/FreeBASIC/gray-code.basic
Normal file
41
Task/Gray-code/FreeBASIC/gray-code.basic
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
' version 18-01-2017
|
||||
' compile with: fbc -s console
|
||||
|
||||
Function gray2bin(g As UInteger) As UInteger
|
||||
|
||||
Dim As UInteger b = g
|
||||
|
||||
While g
|
||||
g Shr= 1
|
||||
b Xor= g
|
||||
Wend
|
||||
|
||||
Return b
|
||||
|
||||
End Function
|
||||
|
||||
Function bin2gray(b As UInteger) As UInteger
|
||||
|
||||
Return b Xor (b Shr 1)
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
Dim As UInteger i
|
||||
|
||||
Print " i binary gray gra2bin"
|
||||
Print String(32,"=")
|
||||
|
||||
For i = 0 To 31
|
||||
Print Using "## --> "; i;
|
||||
print Bin(i,5); " --> ";
|
||||
Print Bin(bin2gray(i),5); " --> ";
|
||||
Print Bin(gray2bin(bin2gray(i)),5)
|
||||
Next
|
||||
|
||||
' empty keyboard buffer
|
||||
While Inkey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue