小编Joh*_*ose的帖子

位掩码的规则是什么?像0xFF vs. 0xFC

我正在制作一个创建程序生成的地牢的游戏,我找到了一个使用位掩码来检索房间号和门类型等内容的例子.

在该示例中,他使用位掩码从每个图块的整数中提取细节.并且整数被这样分解

0xLLSDRRET

L - is the Level Number
S - Denotes a special tile(Like Stairs)
D - is if its a door, and what type(Door, Arch, Trapped)
R - Room number
E - Flags an entrance to a room
T - Names the type of tile(Floor, Cooridor, Blocked)
Run Code Online (Sandbox Code Playgroud)

在这里,他使用一个位掩码来获取,例如,房间号码,如:

int[][] map = new int[40][40] 
int $ROOM_ID = 0x0000FF00;
System.out.println(map[x][y] & $ROOM_ID);
Run Code Online (Sandbox Code Playgroud)

现在有了这个,如果map [x] [y]是例如0x00001200,那么输出将是1200.这部分掩模我明白了.

但在源$ ROOM_ID是ACTUALLY 0x0000FFC0,我不明白C做什么,因为我尝试了不同的值,我似乎无法抓住C做的,例如

0x00001200 output-> 1200
0x00001210 output-> 1200
0x00001220 output-> 1200
0x00001230 output-> 1200 …
Run Code Online (Sandbox Code Playgroud)

java bit-manipulation bitmask bit

6
推荐指数
2
解决办法
8223
查看次数

标签 统计

bit ×1

bit-manipulation ×1

bitmask ×1

java ×1