2008-11-17 13:34:03 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package strconv
|
|
|
|
|
2009-03-02 18:52:58 -07:00
|
|
|
func Itob64(i int64, base uint) string {
|
2008-11-17 13:34:03 -07:00
|
|
|
if i == 0 {
|
|
|
|
return "0"
|
|
|
|
}
|
2008-11-19 13:50:34 -07:00
|
|
|
|
|
|
|
u := uint64(i);
|
2008-11-17 13:34:03 -07:00
|
|
|
if i < 0 {
|
|
|
|
u = -u;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assemble decimal in reverse order.
|
2009-03-02 18:52:58 -07:00
|
|
|
var buf [32]byte;
|
|
|
|
j := len(buf);
|
|
|
|
b := uint64(base);
|
|
|
|
for u > 0 {
|
|
|
|
j--;
|
|
|
|
buf[j] = "0123456789abcdefghijklmnopqrstuvwxyz"[u%b];
|
|
|
|
u /= b;
|
2008-11-17 13:34:03 -07:00
|
|
|
}
|
2009-03-02 18:52:58 -07:00
|
|
|
|
|
|
|
if i < 0 { // add sign
|
|
|
|
j--;
|
|
|
|
buf[j] = '-'
|
2008-11-17 13:34:03 -07:00
|
|
|
}
|
2008-11-19 13:50:34 -07:00
|
|
|
|
2009-03-02 18:52:58 -07:00
|
|
|
return string(buf[j:len(buf)])
|
2008-11-17 13:34:03 -07:00
|
|
|
}
|
|
|
|
|
2009-03-02 18:52:58 -07:00
|
|
|
|
|
|
|
func Itoa64(i int64) string {
|
|
|
|
return Itob64(i, 10);
|
2008-11-17 13:34:03 -07:00
|
|
|
}
|
|
|
|
|
2009-03-02 18:52:58 -07:00
|
|
|
|
|
|
|
func Itob(i int, base uint) string {
|
|
|
|
return Itob64(int64(i), base);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Itoa(i int) string {
|
|
|
|
return Itob64(int64(i), 10);
|
|
|
|
}
|