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
How to transform a 10bit int into two 8bit byte ?
Moderator: Benj
-
- Posts: 594
- Joined: Thu Sep 17, 2009 7:52 am
- Location: Belgium
- Has thanked: 63 times
- Been thanked: 102 times
- Contact:
Re: How to transform a 10bit int into two 8bit byte ?
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
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
-
- Posts: 333
- Joined: Mon Oct 05, 2009 2:39 pm
- Has thanked: 30 times
- Been thanked: 33 times
- Contact:
Re: How to transform a 10bit int into two 8bit byte ?
Thank you for your reply.
I just try in simulation with Flowcode and it works just perfect
Thanks again
I just try in simulation with Flowcode and it works just perfect
Thanks again
- Steve
- Matrix Staff
- Posts: 3422
- Joined: Tue Jan 03, 2006 3:59 pm
- Has thanked: 114 times
- Been thanked: 422 times
- Contact:
Re: How to transform a 10bit int into two 8bit byte ?
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.
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.
-
- Matrix Staff
- Posts: 9520
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
- Contact:
Re: How to transform a 10bit int into two 8bit byte ?
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
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
Last edited by medelec35 on Fri Apr 08, 2011 7:27 am, edited 1 time in total.
Martin