I'm struggling with accessing the individual bytes of the integers used by the Java language. Can someone explain how to access the high and low bytes of an
Ok nevermind. I'll leave this thread up here for anyone else wondering about this. The simplest way to handle this is to create two bytes, a high and a low, and then use this routine to separate the bytes from the int and set them as the high and low bytes :
int x = 375; // this is the word to be separated into a high and low byte. the binary equivalent is 101110111, or high = 1 low = 119
byte high, low;
high = 0;
low = 0;
while (x > 255)
{
x -= 255;
high++;
}
low += x;
Comments
int x = 375; // this is the word to be separated into a high and low byte. the binary equivalent is 101110111, or high = 1 low = 119
byte high, low;
high = 0;
low = 0;
while (x > 255)
{
x -= 255;
high++;
}
low += x;
int low = value16 & 0xFF; //extract lower 8 bits
int high = value16 >>> 8; //extract higher 8 bits
regards peter