Help playing with 12bit bytes ??

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
ellisp83
Posts: 3
Joined: Sat Sep 17, 2011 11:54 pm
Location: uk
Has thanked: 2 times

Help playing with 12bit bytes ??

Post by ellisp83 »

Hi i was hoping sum body could help me?

i want to combine 2 bytes(4bit MSByte + 8bit LSByte) into a single 12bit bit

e.g 1000 combined with 11110000 = 100011110000

Does anyone know of ways of doing this in ASM, C or even flowcode V3?

I would really appreciate anyone's help with this matter :)

Thanks
Ellisp83

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times

Re: Help playing with 12bit bytes ??

Post by JohnCrow »

Hi
Have a look at this way of using a flowchart to combine/split 2 x 8bit bytes. Hope this might help.

http://www.matrixmultimedia.com/mmforum ... ine#p24561
1 in 10 people understand binary, the other one doesn't !

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: Help playing with 12bit bytes ??

Post by medelec35 »

Hi ellisp83,
I believe this is the link John is referring to:
http://www.matrixmultimedia.com/mmforum ... 618#p22618

If you get stuck after reading posts and looking at flowchart John kindly posted then we can help you further.

Martin
Martin

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times

Re: Help playing with 12bit bytes ??

Post by JohnCrow »

Hi Martin
Id just been seaching for your post, to link to that as well :)
1 in 10 people understand binary, the other one doesn't !

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times

Re: Help playing with 12bit bytes ??

Post by Spanish_dude »

Hi,

Code: Select all

int _12_bit_var; // 2 bytes
char _4_bit_MSnibble = 0x08; // 1 byte, 0000 1000
char _8_bit_LSByte = 0xF0; // 1 byte, 1111 0000

_12_bit_var = ((0x0F & _4_bit_MSB) << 8) | _8_bit_LSByte;
That should do it.
If you don't understand it, read Martin's post or just ask if you still don't get it ;).

Nicolas

ellisp83
Posts: 3
Joined: Sat Sep 17, 2011 11:54 pm
Location: uk
Has thanked: 2 times

Re: Help playing with 12bit bytes ??

Post by ellisp83 »

Thanks to all you guys !!!!

I am using this function to combine msbyte and lsbyte of the raw data i recieved from the SHT11 temp and humidity sensor.
So i can then perform the calculation Rhlinear = C1+C2* SOrh+C3*SOrh*
in order to get the true humidity reading to display on my LCD 16x2

Thanks to everyone again !!

Ellisp83

Post Reply