[英]Split uint32 into two uint16
How does one go about splitting a single uint32 var in Go into two uint16 vars, representing the 16 MSB and 16 LSB respectively? go 如何将 Go 中的单个 uint32 变量拆分为两个 uint16 变量,分别代表 16 位 MSB 和 16 位 LSB?
Here is a representation of what I am trying to do:这是我正在尝试做的事情的表示:
var number uint32
var a uint16
var b uint16
number = 4206942069
Now how would one go about assigning the 16 MSB in number
into a
and the 16 LSB into b
?现在 go 如何将 16 MSB
number
给a
并将 16 LSB 分配给b
?
Use the following code to assign the 16 most significant bits in number
to a
and the 16 least significant bits to b
:使用以下代码将数字中的 16 个最高有效位
number
给a
,将 16 个最低有效位分配给b
:
a, b := uint16(number>>16), uint16(number)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.