how to take 2 bytes and convert to a long
mike goettling
Posts: 31
got tunnel vison.
using fullduplexserial program. i need to recive 2 bytes and convert to a·long for data use.
the bytes recived are high byte and low byte of a location pointer.
i need to take the two bytes and create a·long then divde it· by 2
then it is a new pointer location
serial = "fullduplexserial"
long scrprt
byte cursorh
byte cursorl
······ cursorh :=·serial.rx············ get high bit of pointer
······ cursorl :=·· serial.rx··········· get low bit of pointer
·from here i need to take cursorh and cursol and put them in scrprt.
this is where i am stuck. how do i get two bytes into a long.
once they are in the scrprt then i can divde by 2
······· scrprt := scrprt /2
using fullduplexserial program. i need to recive 2 bytes and convert to a·long for data use.
the bytes recived are high byte and low byte of a location pointer.
i need to take the two bytes and create a·long then divde it· by 2
then it is a new pointer location
serial = "fullduplexserial"
long scrprt
byte cursorh
byte cursorl
······ cursorh :=·serial.rx············ get high bit of pointer
······ cursorl :=·· serial.rx··········· get low bit of pointer
·from here i need to take cursorh and cursol and put them in scrprt.
this is where i am stuck. how do i get two bytes into a long.
once they are in the scrprt then i can divde by 2
······· scrprt := scrprt /2
Comments
scrptr := cursorh * 256 + cursorl
-Martin
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Martin Hebel
StampPlot - Graphical Data Acquisition and Control
AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
does not need to be fancy just work
scrprt := cursorh << 7 + cursorl >> 1
this should produce the final result you are looking for.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
I'm confused about this instruction.
7+ ??? wouldn't replace the top bit of the cursorh variable?
Or have I just had my dumb pill today.
James L
scrprt := cursorh << 8 + cursorl
scrprt >>= 1
is the same as
scrprt := cursorh << 7 + cursorl >> 1
only faster the way spin does it's execution.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.fd.com.my
www.mercedes.com.my
No. Internally, everything is stored as a long. If the destination value was a byte, then you'd have a problem, With the destination being a long, you're fine.
I would do it like this:
This way would also work, and is probably quicker:
-Phil
All local variables are longs. I suggest using a local variable (or global long) when performing bit manipulation operations.
Andy
I don't know if you saw post #8 or not. The thread has taken a detour.
and convert it to a signed(+/-) 32 bit long that is divided by 2.
-Phil
Perhaps in 9 years someone exhume this thread again and needs a respond to the original question, just for signed numbers. In that case my respond was not totally useless...
Andy
-Phil
Nice one, and yes, I did notice the date of the original post.
I appreciate the help, I put the suggested code:
TempRaw := (TempMSB << 8) | TempLSB
TempRaw := TempRaw >> 1
I believe that combines the two registers and shifts out the fault code in the LSBit.
Unfortunately I'm back to getting no predictable operation from the Max31865 board. I think I may need to get another part to ensure I'm not beating my head against the wall with a defective part.
Thanks
Joel