是否可以对字符数组进行位掩码 [英] is it possible to bit mask a char array
本文介绍了是否可以对字符数组进行位掩码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有以下char数组
Let's say I have the following char array
char array[32];
我只想使用此数组的10个最高有效位作为哈希值.
I want to use only the 10 most significant bits of this array as a hash value.
是否可以在此char数组上使用按位运算?
Is it possible to use bitwise operation on this char array?
如果是这样,我应该怎么做?
If so, how should i do it?
推荐答案
假设您的实现具有8位的 char
,并且您在此数组中的big endian中存储了256位的数字,这里是如何访问256位数字的10 msb.
Assuming your implementation has 8-bit char
, and that you have a 256-bit number stored in big endian in this array, here how to access the 10 msb of the 256-bit number.
uint16_t a;
a = (array[0] << 2 | (array[1] & 0xC0) >> 6) & 0x3FF;
这篇关于是否可以对字符数组进行位掩码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文