summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-10-11 11:25:36 -0400
committersiddharth <s@ricketyspace.net>2021-10-11 11:25:36 -0400
commit03ce71b250072713270185cd4d035248341c7cdb (patch)
treec59e52649d444df3b730bdb8cccd3cd0595f8b5e
parent1f308c130bd6129c6b74729451cf8c7d70244043 (diff)
lib: add BytesToUint32sLittleEndian
-rw-r--r--lib/byte.go22
1 files changed, 22 insertions, 0 deletions
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)<<ab
+ ab = ab + 8
+ }
+ if ui > 0 {
+ u32s = append(u32s, ui)
+ }
+ return u32s
+}