當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。