splitting 1 byte into 2 bytes

Any general or miscellaneous queries that do not fit into the other forum catagories

Moderators: Benj, Mods

Post Reply
Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

splitting 1 byte into 2 bytes

Post by Ron »

Hi,

I want to read analog input 10 bit, 0 - 1023. I need to separate the high nibble from the low nibble and and put each into it's own byte.

How would I do this?

Thanks

Ron

User avatar
Steve
Matrix Staff
Posts: 3422
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Re: splitting 1 byte into 2 bytes

Post by Steve »

Hi Ron,

I just want to clear up some terminology first... A byte is 8 bits of data and a nibble is half a byte (4 bits of data).

So your question should probably be "How to split up a 10-bit value into 8-bit bytes".

The answer is to use the MOD and / functions as below:

Code: Select all

HiByte = My10BitVal / 256
LoByte = My10BitVal MOD 256

Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Has thanked: 2 times
Contact:

Re: splitting 1 byte into 2 bytes

Post by Ron »

Hi,

yes.... Boy, did I mess that one up......

10 bits.... yep...

Good thing these guys believe in the old saying.... Give me the answer I need, not for what I actually asked...

Thanks,

Ron

Post Reply