Skip to content

Commit 06b84e8

Browse files
authored
change Hash (and RawValue) hex-string representation to show the least-significant field element as big-endian hex string (#338)
* change Hash (and RawValue) hex-string representation to show the least-significant field element as big-endian hex string The motivation is that since some commits ago, the hex representation was changed from little-endian to big-endian, and when cropping the long strings of hex (hex representation of byte-arrays), the small values (224 bits or less) were being represented by `0x00000000...`, which is indistinguishable from the `0` value. This commit updates this cropped representation to print the last characters of the string (the less signifcant bytes of the big-endian representation), so that for example for the integer `5` the representation would be `0x...00000005`.
1 parent e8468d7 commit 06b84e8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/middleware/basetypes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ impl fmt::Display for Hash {
236236
if f.alternate() {
237237
write!(f, "0x{}", self.encode_hex::<String>())
238238
} else {
239-
// display first hex digit in big endian
240-
write!(f, "0x")?;
241-
let v3 = self.0[3].to_canonical_u64();
242-
for i in 0..4 {
243-
write!(f, "{:02x}", (v3 >> ((7 - i) * 8)) & 0xff)?;
239+
// display the least significant field element in big endian
240+
write!(f, "0x")?;
241+
let v0 = self.0[0].to_canonical_u64();
242+
for i in (0..4).rev() {
243+
write!(f, "{:02x}", (v0 >> (i * 8)) & 0xff)?;
244244
}
245-
write!(f, "…")
245+
Ok(())
246246
}
247247
}
248248
}

0 commit comments

Comments
 (0)