单位到二进制传输
对于你们中的一些人来说,这可能是一个愚蠢的问题,但我需要问。 我有这个问题,但我无法弄清楚。如果有人有任何想法,我会很高兴与我分享。 我有一个 UInt64,我必须将其转换为二进制并按 5 位将其拆分为组。 然后根据每组位设置不同的值。 我的问题是我无法找到将其转换为 5 位组的好方法。
之后我将为每个组指定一个不同的值。例如:
00000 - 0
00001 - a
00010 - B
00011 - c
00100 - d
.......
有什么想法或建议吗?
稍后更改该值的最佳方法是什么?我正在考虑一个 Switch
Switch()
{
case "00000" : return 0;
case "00001" : return a;
case "00010" : return B;
case "00011" : return c;
}
这是我想要得到的更多解释。例如我有 64Uint = 1234123;
我想从中得到以下数组:
Array[,] something = new Array[12,5];
This may be a stupid question for some of you but I need to ask.
I have this problem and i could not figure it out. If someone has any idea i will be glad if you'd share it with me.
I have a UInt64 that i have to convert to binary and split it on groups by 5 bits.
And then set a different value depending on each group of bits.
My problem is that I can't figure out a good way to transfer it to groups of 5 bits.
After that i will asign for each group a different value. For example:
00000 - 0
00001 - a
00010 - B
00011 - c
00100 - d
.......
Any ideas or suggestions?
And what is going to be the best way to change the value later? I was thinking about a Switch
Switch()
{
case "00000" : return 0;
case "00001" : return a;
case "00010" : return B;
case "00011" : return c;
}
Here is a little more explanation what i want to get is this. For example i have the 64Uint = 1234123;
From it i want to get the following array:
Array[,] something = new Array[12,5];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 BitConverter.GetBytes() 将 Uint64 转换为字节。
Use BitConverter.GetBytes() to convert a Uint64 to bytes.
您可以使用位掩码将 uint64 分成五个位组:
You can use bitmasks to split the uint64 in groups of five bits: