From 408c501a244bcc35230444f701680c59459b2e40 Mon Sep 17 00:00:00 2001 From: Horki Date: Fri, 5 Mar 2021 22:44:06 +0100 Subject: [PATCH] little endian: present byte order, using std to_le_bytes --- src/lib.rs | 41 +++-------------------------------------- 1 file changed, 3 insertions(+), 38 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 4054725..ba43b8e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,50 +14,15 @@ pub fn now () -> u128 { } pub fn u32_bytes (u: &u32) -> [u8; 4] { - [ - (u >> 8 * 0x0) as u8, - (u >> 8 * 0x1) as u8, - (u >> 8 * 0x2) as u8, - (u >> 8 * 0x3) as u8, - ] + u.to_le_bytes() } pub fn u64_bytes (u: &u64) -> [u8; 8] { - [ - (u >> 8 * 0x0) as u8, - (u >> 8 * 0x1) as u8, - (u >> 8 * 0x2) as u8, - (u >> 8 * 0x3) as u8, - - (u >> 8 * 0x4) as u8, - (u >> 8 * 0x5) as u8, - (u >> 8 * 0x6) as u8, - (u >> 8 * 0x7) as u8, - ] + u.to_le_bytes() } pub fn u128_bytes (u: &u128) -> [u8; 16] { - [ - (u >> 8 * 0x0) as u8, - (u >> 8 * 0x1) as u8, - (u >> 8 * 0x2) as u8, - (u >> 8 * 0x3) as u8, - - (u >> 8 * 0x4) as u8, - (u >> 8 * 0x5) as u8, - (u >> 8 * 0x6) as u8, - (u >> 8 * 0x7) as u8, - - (u >> 8 * 0x8) as u8, - (u >> 8 * 0x9) as u8, - (u >> 8 * 0xa) as u8, - (u >> 8 * 0xb) as u8, - - (u >> 8 * 0xc) as u8, - (u >> 8 * 0xd) as u8, - (u >> 8 * 0xe) as u8, - (u >> 8 * 0xf) as u8, - ] + u.to_le_bytes() } pub fn difficulty_bytes_as_u128 (v: &Vec) -> u128 {