How to transform a 10bit int into two 8bit byte ?

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Mathy
Posts: 333
Joined: Mon Oct 05, 2009 2:39 pm
Has thanked: 30 times
Been thanked: 33 times
Contact:

How to transform a 10bit int into two 8bit byte ?

Post 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

Spanish_dude
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 ?

Post 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

Mathy
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 ?

Post by Mathy »

Thank you for your reply.

I just try in simulation with Flowcode and it works just perfect :)

Thanks again ;)

Mathy
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 ?

Post by Mathy »

in fact, what do the "|" sign mean ?

User avatar
Steve
Matrix Staff
Posts: 3421
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 ?

Post 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.

medelec35
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 ?

Post 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
Last edited by medelec35 on Fri Apr 08, 2011 7:27 am, edited 1 time in total.
Martin

Mathy
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 ?

Post by Mathy »

Many thanks to all of you :)

Post Reply