mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-06 11:54:11 +00:00
@@ -892,14 +892,14 @@ proc toBin*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||
doAssert b.toBin(8) == "00000001"
|
||||
doAssert b.toBin(9) == "100000001"
|
||||
var
|
||||
mask: BiggestInt = 1
|
||||
shift: BiggestInt = 0
|
||||
mask = BiggestUInt 1
|
||||
shift = BiggestUInt 0
|
||||
assert(len > 0)
|
||||
result = newString(len)
|
||||
for j in countdown(len-1, 0):
|
||||
result[j] = chr(int((x and mask) shr shift) + ord('0'))
|
||||
shift = shift + 1
|
||||
mask = mask shl 1
|
||||
result[j] = chr(int((BiggestUInt(x) and mask) shr shift) + ord('0'))
|
||||
inc shift
|
||||
mask = mask shl BiggestUInt(1)
|
||||
|
||||
proc toOct*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||
rtl, extern: "nsuToOct".} =
|
||||
@@ -917,14 +917,14 @@ proc toOct*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||
doAssert b.toOct(3) == "001"
|
||||
doAssert b.toOct(5) == "01001"
|
||||
var
|
||||
mask: BiggestInt = 7
|
||||
shift: BiggestInt = 0
|
||||
mask = BiggestUInt 7
|
||||
shift = BiggestUInt 0
|
||||
assert(len > 0)
|
||||
result = newString(len)
|
||||
for j in countdown(len-1, 0):
|
||||
result[j] = chr(int((x and mask) shr shift) + ord('0'))
|
||||
shift = shift + 3
|
||||
mask = mask shl 3
|
||||
result[j] = chr(int((BiggestUInt(x) and mask) shr shift) + ord('0'))
|
||||
inc shift, 3
|
||||
mask = mask shl BiggestUInt(3)
|
||||
|
||||
proc toHex*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||
rtl, extern: "nsuToHex".} =
|
||||
|
||||
@@ -308,6 +308,13 @@ assert(' '.repeat(0) == "")
|
||||
assert(" ".repeat(0) == "")
|
||||
assert(spaces(0) == "")
|
||||
|
||||
# bug #11369
|
||||
|
||||
var num: int64 = -1
|
||||
assert num.toBin(64) == "1111111111111111111111111111111111111111111111111111111111111111"
|
||||
assert num.toOct(24) == "001777777777777777777777"
|
||||
|
||||
|
||||
# bug #8911
|
||||
when true:
|
||||
static:
|
||||
|
||||
Reference in New Issue
Block a user