将十六进制值拆分为单个组件 [英] Split hex value into individual components
问题描述
我如何将一个十六进制值分成单独的值。
假设我有一个字节0xFF。我怎么会得到一个值是F,第二个是F在Objective-C?我试图在Objective-C中实现SubBytes()过程,显然,SubBytes()步骤包含一个矩阵,其中输出取决于字节的第一个和第二个十六进制表示形式。
下面是一个如何屏蔽/移动要查找的十六进制字节部分的示例:
字节exampleValue = 0x23;
Byte nibble1 = 0x0F& exampleValue;
Byte nibble2 =(0xF0& exampleValue)>> 4;
NSLog(@nibble2 =%d,nibble1 =%d,nibble2,nibble1);
这个例子会给出一个输出:nibble2 = 2,nibble1 = 3
How do I split a hex value into individual values.
Suppose I have a byte, 0xFF. How would I get one value being F and a second being F in Objective-C?
I'm trying to implement the SubBytes() procedure in Objective-C and obviously, the SubBytes() step involves a matrix where the output is dependent on the first and second hex representations of the byte.
Here's an example of how you can mask out / shift the portion of the hex bytes that you're looking for:
Byte exampleValue = 0x23;
Byte nibble1 = 0x0F & exampleValue;
Byte nibble2 = (0xF0 & exampleValue)>>4;
NSLog(@"nibble2 = %d, nibble1 = %d", nibble2, nibble1);
This example will give an output: nibble2 = 2, nibble1 = 3
这篇关于将十六进制值拆分为单个组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!