From 03ce71b250072713270185cd4d035248341c7cdb Mon Sep 17 00:00:00 2001 From: siddharth Date: Mon, 11 Oct 2021 11:25:36 -0400 Subject: lib: add BytesToUint32sLittleEndian --- lib/byte.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib') diff --git a/lib/byte.go b/lib/byte.go index fbdfae9..e97faa1 100644 --- a/lib/byte.go +++ b/lib/byte.go @@ -65,3 +65,25 @@ func BytesToUint32s(bs []byte) []uint32 { } return u32s } + +func BytesToUint32sLittleEndian(bs []byte) []uint32 { + u32s := make([]uint32, 0) + + ui := uint32(0) // 32-bit word. + ab := uint(0) // Occupied bits in ui + for _, b := range bs { + if ab == 32 { + // ui full; add to u32s and reset ui. + u32s = append(u32s, ui) + ui = uint32(0) + ab = 0 + } + // Stuff byte into ui. + ui = ui | uint32(b)< 0 { + u32s = append(u32s, ui) + } + return u32s +} -- cgit v1.2.3