Created
August 2, 2023 13:33
-
-
Save Th0rgal/3ca3765eac3ef54e75e94a4a1d98fc5b to your computer and use it in GitHub Desktop.
An efficient function to convert a FieldElement in a fixed size hexadecimal representation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn to_hex(felt: FieldElement) -> String { | |
let bytes = felt.to_bytes_be(); | |
let mut result = String::with_capacity(bytes.len() * 2 + 2); | |
result.push_str("0x"); | |
for byte in bytes { | |
write!(&mut result, "{:02x}", byte).unwrap(); | |
} | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment