Page 1 of 1
How to transform a 10bit int into two 8bit byte ?
Posted: Wed Apr 06, 2011 9:43 pm
by Mathy
Hello !
I need to transform a 10bit int from an ADC into two 8bit byte to transmit it over RS232.
How to transform this and how to rebuild the 10bit int with the two 8bit byte ?
Thanks a lot for your help,
Mathy
Re: How to transform a 10bit int into two 8bit byte ?
Posted: Wed Apr 06, 2011 9:55 pm
by Spanish_dude
Hi,
I would do something like this :
higher_byte = (ADC_value & 0xFF00) >> 8
lower_byte = (ADC_value & 0xFF)
EDIT:
To rebuild the value after reading it from the rs232 :
ADC_value = higher_byte << 8 | lower_byte
Re: How to transform a 10bit int into two 8bit byte ?
Posted: Thu Apr 07, 2011 9:10 am
by Mathy
Thank you for your reply.
I just try in simulation with Flowcode and it works just perfect
Thanks again

Re: How to transform a 10bit int into two 8bit byte ?
Posted: Thu Apr 07, 2011 9:14 am
by Mathy
in fact, what do the "|" sign mean ?
Re: How to transform a 10bit int into two 8bit byte ?
Posted: Thu Apr 07, 2011 9:38 am
by Steve
Hi Mathy,
There's a great article about this kind of thing here:
http://www.matrixmultimedia.com/mmforum ... =26&t=7451
By the way, the "|" symbol means a bit-wise OR operation. In the example, you can also use a "+" operation.
Re: How to transform a 10bit int into two 8bit byte ?
Posted: Thu Apr 07, 2011 4:08 pm
by medelec35
Hi Mathy,
Take a look at:
http://www.matrixmultimedia.com/mmforum ... igh#p20779
It covers both
10bit into two 8bit
and
From two 8bit into 10bit
I don't disagree with anything posted so far, I just thought would add my 2p worth
,
Martin
Edit. Just read article Steve mentioned. It's definitely worth reading.... Thanks for the link
Re: How to transform a 10bit int into two 8bit byte ?
Posted: Thu Apr 07, 2011 7:16 pm
by Mathy
Many thanks to all of you
