1
0
Fork 0
mirror of synced 2025-09-24 04:40:05 +00:00
ZoKrates/zokrates_stdlib/stdlib/utils/casts/u8_to_field.zok
2021-04-08 13:27:56 +02:00

10 lines
No EOL
254 B
Text

import "EMBED/u8_to_bits" as to_bits
def main(u8 i) -> field:
bool[8] bits = to_bits(i)
field res = 0
for u32 j in 0..8 do
u32 exponent = 8 - j - 1
res = res + if bits[j] then 2 ** exponent else 0 fi
endfor
return res