Splitting byte data in a script

Discuss issues and ideas you have to configuring displays with PowerVision
drphil69
Posts: 139
Joined: Wed Mar 02, 2011 5:59 pm

Splitting byte data in a script

Post by drphil69 » Mon Oct 07, 2013 5:06 pm

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
jdgallaher
Enovation Controls Development
Enovation Controls Development
Posts: 9
Joined: Tue Sep 14, 2010 11:30 am

Re: Splitting byte data in a script

Post by jdgallaher » Wed Oct 09, 2013 3:30 pm

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);
}