View Single Post
Old 01-12-2007, 08:20 AM   #28
sama
FLAC
sama's CarPC Specs
 
sama's Avatar
 
Join Date: Feb 2006
Location: London, UK
Vehicle: BMW 850CSi
Posts: 1,280
My Photos: ()
ok, I was on my lunch break and it just hit me! It's a lot easier than I thought...

the number coming back is not an 8 bit, nor is it a 10 bit. It's 16bit! and we don't need to do anything to it. just need to read it as a 16 bit short integer!

so:

assume the sign byte is 254 and the value byte is 0. We know that 254 means the second-lung and negative. So this should be -255

now we create a short (initialised to 0)
0000 0000 0000 0000

assign the first number (the one that is 0, 1, 254 or 255 - 254 is used as an example):
0000 0000 1111 1110

shift it by 8 bits to the left
1111 1110 0000 0000

do a bitwise xorOR (EDIT:xor would be totally wrong!) with the value (assume 1)
Code:
1111 1110 0000 0000 OR 0000 0001 -------------------- 1111 1110 0000 0001 = -255 (assuming singed short)

Bob's your uncle!
__________________
///Mputer - Velocity - TomTom - Vision - Bezel - CarPC

Last edited by sama : 01-13-2007 at 07:31 AM.
sama is offline   Reply With Quote