@@ -384,19 +384,31 @@ mod tests {
384
384
#[test]
385
385
// docs:start:to_be_radix_example
386
386
fn test_to_be_radix () {
387
- let field = 2 ;
387
+ // 259, in base 256, big endian, is [1, 3].
388
+ // i.e. 3 * 256^0 + 1 * 256^1
389
+ let field = 259 ;
390
+
391
+ // The radix (in this example, 256) must be a power of 2.
392
+ // The length of the returned byte array can be specified to be
393
+ // >= the amount of space needed.
388
394
let bytes : [u8 ; 8 ] = field .to_be_radix (256 );
389
- assert_eq (bytes , [0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 ]);
395
+ assert_eq (bytes , [0 , 0 , 0 , 0 , 0 , 0 , 1 , 3 ]);
390
396
assert_eq (Field ::from_be_bytes ::<8 >(bytes ), field );
391
397
}
392
398
// docs:end:to_be_radix_example
393
399
394
400
#[test]
395
401
// docs:start:to_le_radix_example
396
402
fn test_to_le_radix () {
397
- let field = 2 ;
403
+ // 259, in base 256, little endian, is [3, 1].
404
+ // i.e. 3 * 256^0 + 1 * 256^1
405
+ let field = 259 ;
406
+
407
+ // The radix (in this example, 256) must be a power of 2.
408
+ // The length of the returned byte array can be specified to be
409
+ // >= the amount of space needed.
398
410
let bytes : [u8 ; 8 ] = field .to_le_radix (256 );
399
- assert_eq (bytes , [2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]);
411
+ assert_eq (bytes , [3 , 1 , 0 , 0 , 0 , 0 , 0 , 0 ]);
400
412
assert_eq (Field ::from_le_bytes ::<8 >(bytes ), field );
401
413
}
402
414
// docs:end:to_le_radix_example
0 commit comments