summaryrefslogtreecommitdiff
path: root/util.rkt
diff options
context:
space:
mode:
Diffstat (limited to 'util.rkt')
-rw-r--r--util.rkt8
1 files changed, 8 insertions, 0 deletions
diff --git a/util.rkt b/util.rkt
index aa9714d..5f25e2e 100644
--- a/util.rkt
+++ b/util.rkt
@@ -20,6 +20,7 @@
(provide integer->bytes
integer->bytes/size
bytes->integer
+ bytes->integer/le
pad-bytes
Justification
Endianness
@@ -58,6 +59,13 @@
(bitwise-ior (arithmetic-shift n 8)
byte)))
+(define: (bytes->integer/le [b : Bytes]) : Exact-Nonnegative-Integer
+ (for/fold: ([n : Exact-Nonnegative-Integer 0])
+ ([byte : Byte (in-bytes b)]
+ [i : Integer (in-naturals)])
+ (bitwise-ior (arithmetic-shift byte (* i 8))
+ n)))
+
(define: (pad-bytes [b : Bytes]
[s : Exact-Nonnegative-Integer]
[fill : Byte]