summaryrefslogtreecommitdiff
path: root/src/hal/components/gray2bin.comp
blob: 67788a05e42404f34986d0e869de8addb2c787f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
component gray2bin "convert a gray-code input to binary";
description """Converts a gray-coded number into the corresponding binary value""";
pin in unsigned in "gray code in";
pin out unsigned out "binary code out";
license "GPL";
author "andy pugh";
function _ nofp;
;;
unsigned int mask;
out = in;
for(mask = in >> 1 ; mask != 0 ; mask = mask >> 1){
    out ^= mask;
}