|
merge variables Martin Hug from Spain [6 posts] |
11 year
|
Hello I need to merge two 8 bit values to a 16 bit value.
The line> COG_X_10 = Lo | Hi<<8 gives an error.
My code is:
Hi = GetVariable("COG_X")/256
Lo = GetVariable("COG_X")
COG_X_HI = Hi
COG_X_LO = Lo
COG_X_10 = Lo | Hi<<8
SetVariable"COG_X_HI", COG_X_HI
SetVariable"COG_X_LO", COG_X_LO
SetVariable"COG_X_10", COG_X_10
Thanks Martin
|
|
|
Steven Gentner from United States [1446 posts] |
11 year
|
Martin,
You may have better luck trying the CScript module as VBScript does not have really easy bit operations. Still, I think you can try
Hi = CInt(GetVariable("COG_X") / 256 )
Lo = GetVariable("COG_X") AND 255
COG_X_HI = Hi
COG_X_LO = Lo
COG_X_10 = (Lo * 256) + Hi
SetVariable"COG_X_HI", COG_X_HI
SetVariable"COG_X_LO", COG_X_LO
SetVariable"COG_X_10", COG_X_10
which is a bit different from yours since I figured you are wanting to switch endian (ie swap the bytes) in the number and your's just regenerated the same number. Specifically the COG_X_10 was swapped around.
Note, if you plan to use this is the serial module to send it somewhere you can switch the \ to / and that switches the transmitted endian at least in the serial module.
STeven.
|
|