Combine multiple byte data into single long
dexxterity
Posts: 14
I have three memory locations stored as bytes in memory. I need help on how to combine them into one long. Here is an example of what I am looking to do:
Input:
byte1 = 7
byte_2 = 4
byte_3 = 9
Output:
long_1: 749
Input:
byte1 = 7
byte_2 = 4
byte_3 = 9
Output:
long_1: 749
Comments
Then you can just combine them with:
or will you combine them as bytes of the long like that:
but this will not result in long_1 = 749 decimal. More like: long_1 = $09_04_07
Andy
I depends on the individual values of the bytes. A byte can have a value of zero to 255. If you're sure the three bytes wont exceed 255 then you could store them in a single byte. (Edit: See translation by Phil below.(Thanks Phil.))
Is any one of the three byte ever going to exceed nine? You'd need to use a word to be sure to store any three digit value. If you can be sure the first digit is one or less, then you could safely use a byte to store your three digit number.
-Phil
Yes they will be 0 - 59 (its clock data). It looks like I'll have to work with the three bytes into each long. Thanks for the help everyone.
Total 17bit so you would need a long, unless 2 second count is good enough?
Long := (HH<<12)+(MM<<6)+SS:
word := (HH<<11)+(MM<<5)+SS/2: