arnaucube
arnaucube/circomPublic Self-hosted repository
circom/circuits/tobin.circom
circuits/tobin.circomRaw
 1
 2
 3
 4template toBin(n) {
 5    signal input inp;
 6    signal output out[n];
 7    var lc1=0;
 8
 9    for (var i = 0; i<n; i++) {
10        out[i] <-- (inp >> i) & 1;
11        out[i] * (out[i] -1 ) === 0;
12        lc1 += out[i] * 2**i;
13    }
14
15    lc1 === inp;
16
17}
18
19
20component toBin(3) main;