日常生活的交流与学习

首页 新随笔 联系 管理
  812 随笔 :: 0 文章 :: 2 评论 :: 16万 阅读

golang 十进制数转换成八位二进制数 字节操作 移位操作

package main
import (
"fmt"
)
func main() {
mapOne := []byte{191, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 253}
var mapTwo []byte
// // 将每个字节的每一位分离出来并存入binaryDigits
for _, b := range mapOne {
fmt.Printf(" %08b ", b)
fmt.Printf("%v_", byte((b>>uint(7-0))&1))
fmt.Printf("%v_", byte((b>>uint(7-1))&1))
fmt.Printf("%v_", byte((b>>uint(7-2))&1))
fmt.Printf("%v_", byte((b>>uint(7-3))&1))
fmt.Println()
for j := 0; j < 8; j++ {
// 使用位移和按位与操作检查每一位
mapTwo = append(mapTwo, byte((b>>uint(7-j))&1))
}
}
fmt.Println()
fmt.Println(mapTwo)
}
10111111 1_0_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111111 1_1_1_1_
11111101 1_1_1_1_
[1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1]
posted on 2025-02-12 10:42  宇宙无敌美少男战士  阅读(0)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek-R1本地部署如何选择适合你的版本?看这里
· 开源的 DeepSeek-R1「GitHub 热点速览」
· 传国玉玺易主,ai.com竟然跳转到国产AI
· 揭秘 Sdcb Chats 如何解析 DeepSeek-R1 思维链
· 自己如何在本地电脑从零搭建DeepSeek!手把手教学,快来看看! (建议收藏)
历史上的今天:
2024-02-12 asp.net 托管服务 后台任务 定时器任务
2023-02-12 cnblog_fastapi 中的 schemas 和 models 的区别
2023-02-12 fastapi_docs_src_官网教程
2023-02-12 code2markdown_macbook
2023-02-12 redis_python_连接
2023-02-12 sqlalchemy_python_mysql
2022-02-12 css 四种基本选择器
点击右上角即可分享
微信分享提示