Split hex value into individual components

喜欢而已 提交于 2019-12-12 03:05:47

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/19372820/split-hex-value-into-individual-components

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!