# convert to little endian

Discussion in 'Java' started by mike, Oct 20, 2004.

1. ### mikeGuest

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.

mike, Oct 20, 2004

2. ### Thomas FritschGuest

mike wrote:
> 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?

--
"Thomas:Fritsch\$ops:de".replace(':','.').replace('\$','@')

Thomas Fritsch, Oct 20, 2004

3. ### hilzGuest

> "Thomas:Fritsch\$ops:de".replace(':','.').replace('\$','@')

nice!

hilz, Oct 20, 2004
4. ### Thomas G. MarshallGuest

hilz coughed up:
>> "Thomas:Fritsch\$ops:de".replace(':','.').replace('\$','@')

>
> nice!

What he said. That's kinda nifty.

--
Framsticks. 3D Artificial Life evolution. You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/

Thomas G. Marshall, Oct 21, 2004

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.