diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2015-02-19 09:12:50 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2015-02-19 09:12:50 +0100 |
commit | 43c023c8ddaf5f6f4aee321fb042b5bdd8339fce (patch) | |
tree | 5bdc5e1e868cce8d436e4b810b04951149656fb4 /lib/pure | |
parent | a8acb5ec65b5a3d6577602b9fc0d8832cf3a3287 (diff) | |
parent | a471b3c87fa3be6f9a5042ba8b814762118d4a07 (diff) | |
download | Nim-43c023c8ddaf5f6f4aee321fb042b5bdd8339fce.tar.gz |
Merge pull request #2164 from oderwat/fix-tohex
Fixing toHex() to not wrap for long lens + Test
Diffstat (limited to 'lib/pure')
-rw-r--r-- | lib/pure/strutils.nim | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/pure/strutils.nim b/lib/pure/strutils.nim index 17e0b9e63..39f468ee3 100644 --- a/lib/pure/strutils.nim +++ b/lib/pure/strutils.nim @@ -395,11 +395,13 @@ proc toHex*(x: BiggestInt, len: int): string {.noSideEffect, const HexChars = "0123456789ABCDEF" var - shift: BiggestInt + n = x result = newString(len) for j in countdown(len-1, 0): - result[j] = HexChars[toU32(x shr shift) and 0xF'i32] - shift = shift + 4 + result[j] = HexChars[n and 0xF] + n = n shr 4 + # handle negative overflow + if n == 0 and x < 0: n = -1 proc intToStr*(x: int, minchars: int = 1): string {.noSideEffect, rtl, extern: "nsuIntToStr".} = |