var b byte = 0b00001111
shifted := b << 4 //向左移动 4 位
result := shifted | b // 按位或
result2 := shifted & b // 按位与
result3 := shifted ^ 0b00010000 // 按位异或
result4 := ^b // 按位取反
result5 := b &^ 0b00000100 // 按位清除
fmt.Printf("b:%08b\n", b) //00001111
fmt.Printf("shifted:%08b\n", shifted) // 11110000
fmt.Printf("result:%08b\n", result) // 11111111
fmt.Printf("result2:%08b\n", result2) // 00000000
fmt.Printf("result3:%08b\n", result3) // 11100000
fmt.Printf("result4:%08b\n", result4) // 11110000
fmt.Printf("result5:%08b\n", result5) // 00001011
fmt.Println(string(strconv.AppendInt([]byte{}, int64(b), 2))) // 1111
网友评论