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

Categories

0 votes
237 views
in Technique[技术] by (71.8m points)

objective c - Split hex value into individual components

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

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

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...