Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
241 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
...