C中的typedef枚举中的十六进制 [英] hexadecimal in typedef enum in C
问题描述
我正在搜索C中的 typedef枚举
中使用十六进制的原因。
I was searching for the reason behind using hexadecimal in typedef enum
in C.
我遵循以下内容链接,但有两个答案:
c,obj c没有标签或标识符的枚举器
I followed the following link, but there are two answers: c, obj c enum without tag or identifier
LearnCocos2D表示,em并没有增加使用十六进制数字,特别是没有启动十六进制数字一个通过f(10到15)。
LearnCocos2D says that, "there's no gain to use hex numbers and in particular there's no point in starting the hex numbers with a through f (10 to 15). "
Sulthan说,当整数是二进制掩码时,通常使用十六进制数。我搜索了二进制掩码,并明白,它的一个技术用于位图游戏从以下链接 https://en.wikipedia.org/wiki/Mask_(computing)
Sulthan says that, "Hexadecimal numbers are commonly used when the integer is a binary mask". I searched for binary mask and came to understand that, its a technique used in bitmap gaming from following link https://en.wikipedia.org/wiki/Mask_(computing)
如果sulthan是对的,请帮我理解。
If sulthan is right, kindly help me understand it.
我没有足够的声誉来评论,所以我创建了这个新的问题。
I don't have enough reputation to comment, so I created this as new question.
推荐答案
对于一个位掩码,它有助于查看二进制值,因为这是一个位掩码所需的级别。而每个枚举值通常只设置一个位。
For a bit mask it helps to look at values in binary since that is the level needed for a bit mask. And each enum value typically only sets a single bit.
所以枚举值将被设置(二进制)到 00001
, 00010
, 00100
, 01000
, 10000
等。
So the enum values would be set (in binary) to 00001
, 00010
, 00100
, 01000
, 10000
, etc.
十进制中相同的值将为: 1
, 2
, 4
, 8
,code> 16 等。
Those same values in decimal would be: 1
, 2
, 4
, 8
, 16
, etc.
在十六进制中,它们将是 0x01
, 0x02
, 0x04
, 0x08
, 0x10
等。
And in hex they would be 0x01
, 0x02
, 0x04
, 0x08
, 0x10
, etc.
这真的只是一个偏好的问题,但由于十六进制是2的幂,它更好地涉及二进制十进制。这使得它稍微更清楚,值代表位掩码值。
It's really just a matter of preference but since hexadecimal is a power of 2, it better relates to binary than decimal does. This makes it slightly clearer that the values represent bit mask values.
这篇关于C中的typedef枚举中的十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!