convert to little endian

M

mike

Trying to convert the following to little endian. I have set up my
long bits but dont know how to shift the bits correctly. Heres what I
have at the moment.

long lgn = 0;
long l = Double.doubleToLongBits(dbl);
for (int shift = 0; shift < 64; shift+=8)
{
lgn |= l & 0xff << shiftBy;
}
Any help would be great.
 
T

Thomas Fritsch

mike said:
Trying to convert the following to little endian. I have set up my
long bits but dont know how to shift the bits correctly. Heres what I
have at the moment.
Convert to little-endian from what? From little-endian or from
big-endian? Currently your algorithm converts from little-endian to
little-endian; your end-result is simply lgn == l.
long lgn = 0;
long l = Double.doubleToLongBits(dbl);
for (int shift = 0; shift < 64; shift+=8)
{
lgn |= l & 0xff << shiftBy;
You probably mean 'shift' here, not 'shiftby' which isn't declared.
Also: Please use parentheses here, to clarify what you intend.
lgn |= (l & 0xff) << shiftBy;
or lgn |= l & (0xff << shiftBy);
(Because the rules of precedence are easy to remember for compilers, but
hard for humans.)
}
Any help would be great.
Please refine your problem description! What do you want to achieve?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top