Hello,
I am trying to split a two byte value into separate bytes within a script. I *thought* I knew how, but it doesn't seem to be working properly. I also cannot properly test it here so I am uncertain if this is the issue, and would like to eliminate it if possible.
For the low byte:
VAR = VAR & 0x00FF; //masks high byte
For the high byte:
VAR = (VAR & 0xFF00) / 0x100; //masks low byte then shift right by div 0x100
Am I doing something wrong?
Thanks,
Phil
Splitting byte data in a script
- drphil69
- Posts: 139
- Joined: Wed Mar 02, 2011 5:59 pm
- jdgallaher
- Enovation Controls Development
- Posts: 9
- Joined: Tue Sep 14, 2010 11:30 am
Re: Splitting byte data in a script
Phil,
I just ran a test on a unit, the following script correctly split the high and low bytes out. The smRead and smWrite were so I could manipulate the data and see the results.
Derek
void $SplitBytes$ ()
{
uint InitialByte;
uint highByte;
uint lowByte;
smRead(VariableIDs.InitialByte, InitialByte);
lowByte = InitialByte & 0xFF;
highByte = (InitialByte & 0xFF00)>>8;
smWrite(VariableIDs.HighByte, highByte);
smWrite(VariableIDs.LowByte, lowByte);
}
I just ran a test on a unit, the following script correctly split the high and low bytes out. The smRead and smWrite were so I could manipulate the data and see the results.
Derek
void $SplitBytes$ ()
{
uint InitialByte;
uint highByte;
uint lowByte;
smRead(VariableIDs.InitialByte, InitialByte);
lowByte = InitialByte & 0xFF;
highByte = (InitialByte & 0xFF00)>>8;
smWrite(VariableIDs.HighByte, highByte);
smWrite(VariableIDs.LowByte, lowByte);
}