Menu

[r376]: / XGRAYCOD.MPL  Maximize  Restore  History

Download this file

21 lines (15 with data), 350 Bytes

/*
  GRAYCODE - MPL VERSION
  BASED ON THE C VERSION
  HTTPS://ROSETTACODE.ORG/WIKI/GRAY_CODE#C
*/

##LIBHDR

GRAY.ENCODE(N) N^>>N
GRAY.DECODE(N;P) [ P=N; (N>>=1) @ P^=N; P ]

.(;N,G,B) [
  N=0; N<32 @ [
    B=GRAY.DECODE(G=GRAY.ENCODE(N));
    WRITEF("%I2 : %B5 => %B5 => %B5 : %I2 %S*N",N,N,G,B,B,N<>B?"ERROR");
    ++N
  ]
]

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.