Skip to content

Instantly share code, notes, and snippets.

@Th0rgal
Created August 2, 2023 13:33
Show Gist options
  • Save Th0rgal/3ca3765eac3ef54e75e94a4a1d98fc5b to your computer and use it in GitHub Desktop.
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
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