问题描述
我需要从可能(不)包含CHAR_BIT位的倍数位集extact字节。我现在有多少位集的位,我需要投入一个数组。例如,
I need to extact bytes from the bitset which may (not) contain a multiple of CHAR_BIT bits. I now how many of the bits in the bitset I need to put into an array. For example,
设置声明位为和std :: bitset< 40 GT; ID;
有一个单独的变量 NBITS
有多少位的 ID
是可用的。现在,我想在CHAR_BIT的倍数来提取这些位。我也需要照顾的情况下,其中 NBITS%CHAR_BIT!= 0
。我好把这个变成UINT8数组
There is a separate variable nBits
how many of the bits in id
are usable. Now I want to extract those bits in multiples of CHAR_BIT. I also need to take care of cases where nBits % CHAR_BIT != 0
. I am okay to put this into an array of uint8
推荐答案
不幸的是还有的语言中没有什么好办法,假设你需要比位在数无符号长
(在这种情况下,你可以使用 to_ulong
)。你必须遍历所有的位,并生成字节数组自己。
Unfortunately there's no good way within the language, assuming you need for than the number of bits in an unsigned long
(in which case you could use to_ulong
). You'll have to iterate over all the bits and generate the array of bytes yourself.
这篇关于如何转换为的BitSet字节/ UINT8数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!