func main() { counter := 0 var str string for _, i := range []byte("foobar") { letterBin := fmt.Sprintf("%08b", i) fmt.Println(letterBin) str = str + letterBin counter = counter + len(letterBin) } fmt.Println() fmt.Printf("%010d",counter) counter = 0 for _, l := range str { if l == int32('1') { counter++ } } fmt.Println() fmt.Println(counter) }
zzh@ZZHPC:/zdata/Github/orders-api$ go run main.go 01100110 01101111 01101111 01100010 01100001 01110010 0000000048 26
标签:fmt,counter,when,number,printing,str,Println,letterBin From: https://www.cnblogs.com/zhangzhihui/p/17975131