'-------------------------------------------------------------------------------
'                               (c) 2001-2003 MCS Electronics
' This sample show the Bin2Grey and Grey2Bin functions
' Credits to Josef Franz Vögel for an improved and word/long extended version
'-------------------------------------------------------------------------------

'Bin2Gey() converts a byte,integer,word or long into grey code.
'Grey2Bin() converts a grey code into a binary value

Dim B As Byte                                               ' could be word,integer or long too

Print "BIN" ; Spc(8) ; "GREY"
For B = 0 To 15
  Print B ; Spc(10) ; Bin2grey(b)
Next

Print "GREY" ; Spc(8) ; "BIN"
For B = 0 To 15
  Print B ; Spc(10) ; Grey2bin(b)
Next

End