当前位置: 首页>>代码示例>>Golang>>正文


Golang strconv.Itob函数代码示例

本文整理汇总了Golang中strconv.Itob函数的典型用法代码示例。如果您正苦于以下问题:Golang Itob函数的具体用法?Golang Itob怎么用?Golang Itob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Itob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: charString

func charString(ch int) string {
	var s string
	switch ch {
	case -1:
		return `EOF`
	case '\a':
		s = `\a`
	case '\b':
		s = `\b`
	case '\f':
		s = `\f`
	case '\n':
		s = `\n`
	case '\r':
		s = `\r`
	case '\t':
		s = `\t`
	case '\v':
		s = `\v`
	case '\\':
		s = `\\`
	case '\'':
		s = `\'`
	default:
		s = string(ch)
	}
	return "'" + s + "' (U+" + strconv.Itob(ch, 16) + ")"
}
开发者ID:richlowe,项目名称:gcc,代码行数:28,代码来源:scanner.go

示例2: main

func main() {
	if five_as_bool := strconv.Itob(5); five_as_bool {
		fmt.Printf("True\n")
	} else {
		fmt.Printf("False\n")
	}
}
开发者ID:sbhackerspace,项目名称:sbhx-snippets,代码行数:7,代码来源:bool.go

示例3: charString

func charString(ch int) string {
	var s string;
	switch ch {
	case -1:
		return `EOF`;
	case '\a':
		s = `\a`;
	case '\b':
		s = `\b`;
	case '\f':
		s = `\f`;
	case '\n':
		s = `\n`;
	case '\r':
		s = `\r`;
	case '\t':
		s = `\t`;
	case '\v':
		s = `\v`;
	case '\\':
		s = `\\`;
	case '\'':
		s = `\'`;
	default:
		s = string(ch);
	}
	return "'" + s + "' (U+" + strconv.Itob(ch, 16) + ")";
}
开发者ID:8l,项目名称:go-learn,代码行数:28,代码来源:scanner.go

示例4: version

// The SQLite database interface returns keys "version",
// "sqlite3.sourceid", and "sqlite3.versionnumber"; the
// latter are specific to SQLite.
func version() (data map[string]string, error os.Error) {
	// TODO: fake client and server keys?
	data = make(map[string]string)
	data["version"] = sqlVersion()
	i := sqlVersionNumber()
	data["sqlite3.versionnumber"] = strconv.Itob(i, 10)
	data["sqlite3.sourceid"] = sqlSourceId()
	return
}
开发者ID:phf,项目名称:go-sqlite3,代码行数:12,代码来源:core.go

示例5: main

func main() {
	sum := 0
	for i := 1; i < 1000000; i++ {
		if palidrome(strconv.Itoa(i)) &&
			palidrome(strconv.Itob(i, 2)) {
			sum += i
		}
	}
	fmt.Printf("%d\n", sum)
}
开发者ID:yyyc514,项目名称:project_euler_in_go,代码行数:10,代码来源:problem36.go

示例6: Euler36

func Euler36() string {
	sum := 0
	for i := 1; i < 1000000; i++ {
		if palidrome(strconv.Itoa(i)) &&
			palidrome(strconv.Itob(i, 2)) {
			sum += i
		}
	}
	return fmt.Sprint(sum)
}
开发者ID:Narsil,项目名称:go-euler,代码行数:10,代码来源:problem36.go

示例7: TestFizzBuzz

func TestFizzBuzz(t *testing.T) {
	var numbers = FizzBuzz()
	if len(numbers) != 100 {
		t.Errorf("100 items expected.")
	}
	var number int
	for i := 0; i < len(numbers); i++ {
		number = i + 1
		if number%5 == 0 && number%3 == 0 && !strings.Contains(numbers[i], "FizzBuzz") {
			t.Errorf("Expecting FizzBuzz for %d. Found %s.", number, numbers[i])
		} else if number%5 == 0 && !strings.Contains(numbers[i], "Buzz") {
			t.Errorf("Expecting Buzz for %d. Found %s.", number, numbers[i])
		} else if number%3 == 0 && !strings.Contains(numbers[i], "Fizz") {
			t.Errorf("Expecting Fizz for %d. Found %s.", number, numbers[i])
		} else if number%5 != 0 && number%3 != 0 && !strings.Contains(numbers[i], strconv.Itob(number, 10)) {
			t.Errorf("Expecting %s at %d. Found %s.", strconv.Itob(number, 10), i, numbers[i])
		}
	}
}
开发者ID:robertrv,项目名称:Marzo-FizzBuzz,代码行数:19,代码来源:fizzbuzz_test.go

示例8: main

func main() {
	sum := 0
	for i := 0; i < 1000000; i++ {
		if isPalindrome(strconv.Itoa(i)) {
			if isPalindrome(strconv.Itob(i, 2)) {
				sum += i
			}
		}
	}
	println(sum)
}
开发者ID:zengin,项目名称:project-euler-solutions,代码行数:11,代码来源:036.go

示例9: TestHexDecode

func TestHexDecode(t *testing.T) {
	for i := 0; i < 0x200000; i += 101 /* coprime with 16 */ {
		s := strconv.Itob(i, 16)
		if got := int(hexDecode([]byte(s))); got != i {
			t.Errorf("%s: want %d but got %d", s, i, got)
		}
		s = strings.ToUpper(s)
		if got := int(hexDecode([]byte(s))); got != i {
			t.Errorf("%s: want %d but got %d", s, i, got)
		}
	}
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:12,代码来源:css_test.go

示例10: escape

func escape(b *bytes.Buffer, r int, force bool) {
	if unicode.IsPrint(r) {
		if strings.IndexRune(meta, r) >= 0 || force {
			b.WriteRune('\\')
		}
		b.WriteRune(r)
		return
	}

	switch r {
	case '\a':
		b.WriteString(`\a`)
	case '\f':
		b.WriteString(`\f`)
	case '\n':
		b.WriteString(`\n`)
	case '\r':
		b.WriteString(`\r`)
	case '\t':
		b.WriteString(`\t`)
	case '\v':
		b.WriteString(`\v`)
	default:
		if r < 0x100 {
			b.WriteString(`\x`)
			s := strconv.Itob(r, 16)
			if len(s) == 1 {
				b.WriteRune('0')
			}
			b.WriteString(s)
			break
		}
		b.WriteString(`\x{`)
		b.WriteString(strconv.Itob(r, 16))
		b.WriteString(`}`)
	}
}
开发者ID:WXB506,项目名称:golang,代码行数:37,代码来源:regexp.go

示例11: FizzBuzz

func FizzBuzz() [100]string {
	numbers := [100]string{}
	fizzOrBuzzOrFizzBuzzOrNumber := ""
	for i := 1; i < 101; i++ {
		if i%5 == 0 && i%3 == 0 {
			fizzOrBuzzOrFizzBuzzOrNumber = "FizzBuzz"
		} else if i%3 == 0 {
			fizzOrBuzzOrFizzBuzzOrNumber = "Fizz"
		} else if i%5 == 0 {
			fizzOrBuzzOrFizzBuzzOrNumber = "Buzz"
		} else {
			fizzOrBuzzOrFizzBuzzOrNumber = strconv.Itob(i, 10)
		}
		numbers[i-1] = fizzOrBuzzOrFizzBuzzOrNumber
	}
	return numbers
}
开发者ID:robertrv,项目名称:Marzo-FizzBuzz,代码行数:17,代码来源:fizzbuzz.go

示例12: Write

func (c chunkedWriter) Write(p []byte) (int, os.Error) {
	if c.responseErr != nil {
		return 0, c.responseErr
	}
	if len(p) == 0 {
		return 0, nil
	}
	_, c.responseErr = io.WriteString(c.netConn, strconv.Itob(len(p), 16)+"\r\n")
	if c.responseErr != nil {
		return 0, c.responseErr
	}
	var n int
	n, c.responseErr = c.netConn.Write(p)
	if c.responseErr != nil {
		return n, c.responseErr
	}
	_, c.responseErr = io.WriteString(c.netConn, "\r\n")
	return 0, c.responseErr
}
开发者ID:andradeandrey,项目名称:twister,代码行数:19,代码来源:server.go

示例13: GoSet

func (f *File) GoSet(which Field) {
	if which == 0 {
		return
	} // Nothing to set!
	ago.Import("github.com/droundy/goadmin/file")
	ago.Declare("var changed_files = make(map[string]bool)")
	ago.Declare("var file_changed = false")
	ago.Declare("var this_file_changed = false")
	ago.Declare("var myf file.File")
	code := "myf = file.File{file.StatData{" + strconv.Quote(f.Name) + ","
	code += fmt.Sprint(f.Uid, ",", f.Gid, ", 0", strconv.Itob(int(f.Perms), 8), ", file.IsFile},")
	if Contents&which != 0 {
		code += strconv.Quote(f.Contents) + "}"
	} else {
		code += `""}`
	}
	code += fmt.Sprint("\n\tthis_file_changed, e = myf.Set(", which, ")")
	code += fmt.Sprint("\n\tif e != nil { fmt.Println(`Trouble setting", f.Name, ":`,e); return }")
	code += fmt.Sprint("\n\tif this_file_changed { changed_files[`", f.Name, "`] = true }")
	code += fmt.Sprint("\n\tfile_changed = file_changed || this_file_changed")
	ago.Code(code)
}
开发者ID:andradeandrey,项目名称:goadmin,代码行数:22,代码来源:file.go

示例14: Write

// Write the contents of data as one chunk to Wire.
// NOTE: Note that the corresponding chunk-writing procedure in Conn.Write has
// a bug since it does not check for success of io.WriteString
func (cw *chunkedWriter) Write(data []byte) (n int, err error) {

	// Don't send 0-length data. It looks like EOF for chunked encoding.
	if len(data) == 0 {
		return 0, nil
	}

	head := strconv.Itob(len(data), 16) + "\r\n"

	if _, err = io.WriteString(cw.Wire, head); err != nil {
		return 0, err
	}
	if n, err = cw.Wire.Write(data); err != nil {
		return
	}
	if n != len(data) {
		err = io.ErrShortWrite
		return
	}
	_, err = io.WriteString(cw.Wire, "\r\n")

	return
}
开发者ID:aubonbeurre,项目名称:gcc,代码行数:26,代码来源:chunked.go

示例15: TestHandshakeServerAES

}

func TestHandshakeServerAES(t *testing.T) {
	aesConfig := new(Config)
	*aesConfig = *testConfig
	aesConfig.CipherSuites = []uint16{TLS_RSA_WITH_AES_128_CBC_SHA}
	testServerScript(t, "AES", aesServerScript, aesConfig)
}

func TestHandshakeServerSSLv3(t *testing.T) {
	testServerScript(t, "SSLv3", sslv3ServerScript, testConfig)
}

var serve = flag.Bool("serve", false, "run a TLS server on :10443")
var testCipherSuites = flag.String("ciphersuites",
	"0x"+strconv.Itob(int(TLS_RSA_WITH_RC4_128_SHA), 16),
	"cipher suites to accept in serving mode")

func TestRunServer(t *testing.T) {
	if !*serve {
		return
	}

	suites := strings.Split(*testCipherSuites, ",")
	testConfig.CipherSuites = make([]uint16, len(suites))
	for i := range suites {
		suite, err := strconv.Btoui64(suites[i], 0)
		if err != nil {
			panic(err)
		}
		testConfig.CipherSuites[i] = uint16(suite)
开发者ID:Quantumboost,项目名称:gcc,代码行数:31,代码来源:handshake_server_test.go


注:本文中的strconv.Itob函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。