ZhangZhihui's Blog  

 

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

 

posted on 2024-01-19 17:12  ZhangZhihuiAAA  阅读(10)  评论(0)    收藏  举报