问题
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