二進(jìn)制相關(guān)

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
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容