gpt4 book ai didi

c# - 把10位数和6位数写成short?

转载 作者:行者123 更新时间:2023-11-30 19:18:37 25 4
gpt4 key购买 nike

我正在编写一个程序,其中一个数字(10 位数字)存储在 16 位数字的第一部分,然后 6 位数字存储在末尾。

我如何利用位移来实现我的目标?

最佳答案

注意:我将“16 位数字的第一部分”解释为“10 个最低有效位”——因为位数学通常从右向后计数。

short x = (short)(value & 1023); // the first 10 bits
short y = (short)((value >> 10) & 63); // the last 6 bits

并重组:

value = (short)(x | (y << 10));

关于c# - 把10位数和6位数写成short?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12012634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com