mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-03 12:34:44 +00:00
Enable range checking for unsigned integers (#11313)
* Enable range checking for unsigned integers * Make the tests green
This commit is contained in:
committed by
Andreas Rumpf
parent
70fb3a93e9
commit
3a06022071
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user