Getting nybbles

M

mikew01

Hi, I need to split up a byte value into two nybbles, I understand bit
shifting is the ideal method to perform this task.

Could someone explain how to do this please.

TIA
 
D

Daniel Pitts

Hi, I need to split up a byte value into two nybbles, I understand bit
shifting is the ideal method to perform this task.

Could someone explain how to do this please.

TIA

Well, a nibble is 4 bits, and a byte is 8 bits.

You need to mask part of the byte using binary and (&). 00001111 in
binary = 15 dec and 0xF hex.

lowNib = myByte & 0xF;

Then you need to make the high nibble in myByte the low nibble:

highNib = (myByte >> 4) & 0xF;

Hope this explains it. Good luck,
Daniel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top