parent
c02320e230
commit
5eb47f8ed9
2 changed files with 17 additions and 10 deletions
|
|
@ -892,14 +892,14 @@ proc toBin*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||||
doAssert b.toBin(8) == "00000001"
|
doAssert b.toBin(8) == "00000001"
|
||||||
doAssert b.toBin(9) == "100000001"
|
doAssert b.toBin(9) == "100000001"
|
||||||
var
|
var
|
||||||
mask: BiggestInt = 1
|
mask = BiggestUInt 1
|
||||||
shift: BiggestInt = 0
|
shift = BiggestUInt 0
|
||||||
assert(len > 0)
|
assert(len > 0)
|
||||||
result = newString(len)
|
result = newString(len)
|
||||||
for j in countdown(len-1, 0):
|
for j in countdown(len-1, 0):
|
||||||
result[j] = chr(int((x and mask) shr shift) + ord('0'))
|
result[j] = chr(int((BiggestUInt(x) and mask) shr shift) + ord('0'))
|
||||||
shift = shift + 1
|
inc shift
|
||||||
mask = mask shl 1
|
mask = mask shl BiggestUInt(1)
|
||||||
|
|
||||||
proc toOct*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
proc toOct*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||||
rtl, extern: "nsuToOct".} =
|
rtl, extern: "nsuToOct".} =
|
||||||
|
|
@ -917,14 +917,14 @@ proc toOct*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||||
doAssert b.toOct(3) == "001"
|
doAssert b.toOct(3) == "001"
|
||||||
doAssert b.toOct(5) == "01001"
|
doAssert b.toOct(5) == "01001"
|
||||||
var
|
var
|
||||||
mask: BiggestInt = 7
|
mask = BiggestUInt 7
|
||||||
shift: BiggestInt = 0
|
shift = BiggestUInt 0
|
||||||
assert(len > 0)
|
assert(len > 0)
|
||||||
result = newString(len)
|
result = newString(len)
|
||||||
for j in countdown(len-1, 0):
|
for j in countdown(len-1, 0):
|
||||||
result[j] = chr(int((x and mask) shr shift) + ord('0'))
|
result[j] = chr(int((BiggestUInt(x) and mask) shr shift) + ord('0'))
|
||||||
shift = shift + 3
|
inc shift, 3
|
||||||
mask = mask shl 3
|
mask = mask shl BiggestUInt(3)
|
||||||
|
|
||||||
proc toHex*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
proc toHex*(x: BiggestInt, len: Positive): string {.noSideEffect,
|
||||||
rtl, extern: "nsuToHex".} =
|
rtl, extern: "nsuToHex".} =
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,13 @@ assert(' '.repeat(0) == "")
|
||||||
assert(" ".repeat(0) == "")
|
assert(" ".repeat(0) == "")
|
||||||
assert(spaces(0) == "")
|
assert(spaces(0) == "")
|
||||||
|
|
||||||
|
# bug #11369
|
||||||
|
|
||||||
|
var num: int64 = -1
|
||||||
|
assert num.toBin(64) == "1111111111111111111111111111111111111111111111111111111111111111"
|
||||||
|
assert num.toOct(24) == "001777777777777777777777"
|
||||||
|
|
||||||
|
|
||||||
# bug #8911
|
# bug #8911
|
||||||
when true:
|
when true:
|
||||||
static:
|
static:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue