Enable range checking for unsigned integers (#11313)

* Enable range checking for unsigned integers

* Make the tests green
This commit is contained in:
Oscar Nihlgård
2019-05-25 20:48:13 +02:00
committed by Andreas Rumpf
parent 70fb3a93e9
commit 3a06022071
5 changed files with 24 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ proc toByteArrayBE*[T: SomeInteger](num: T): ByteArrayBE[sizeof(T)]=
## Notice the result type
const N = T.sizeof
for i in 0 ..< N:
result[i] = byte(num shr ((N-1-i) * 8))
result[i] = byte((num shr ((N-1-i) * 8)) and high(int8))
let a = 12345.toByteArrayBE
echo a[^2 .. ^1] # to make it work on both 32-bit and 64-bit