View difference between Paste ID: apLYUKHb and 66Jh1aBc
SHOW: | | - or go back to the newest paste.
1
component gray2bin "convert a gray-code input to binary";
2
3
pin in unsigned in "gray code in";
4
pin out unsigned out "gray code out";
5
6
license "GPL";
7
author "andy pugh";
8
function _;
9
10
;;
11
12
u32 mask;
13-
for(mask = in >> 1 ; mask != 0 ; mask = mask >> 1){
13+
u32 num = in;
14-
    out ^= mask;
14+
for(mask = num >> 1 ; mask != 0 ; mask = mask >> 1){
15-
}
15+
    num ^= mask;
16
}
17
out = num;