golang byte转string乱码_go byte转string

golang byte转string乱码_go byte转stringfuncBytesToString(bs[]byte)string{l:=len(bs)buf:=make([]string,0,l)fori:=0;i

func BytesToString(bs []byte) string {
    l := len(bs)
    buf := make([]string, 0, l)
    for i := 0; i < l; i++ {
        buf = appendString(buf, bs[i])
    }
    return strings.Join(buf, dot)
}

func appendString(bs []string, b byte) []string {
    var a byte
    var s int
    for i := 0; i < 8; i++ {
        a = b
        b <<= 1
        b >>= 1
        switch a {
        case b:
            s += 0
        default:
            temp := 1
            for j := 0; j < 7 - i; j++ {
                temp = temp*2
            }
            s += temp
        }

        b <<= 1
    }

    return append(bs, strconv.Itoa(s))
}
只听到从架构师办公室传来架构君的声音:
道人庭宇静,苔色连深竹。有谁来对上联或下联?
本文来源疯狂的__石头,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/211949
0

发表评论