Velocity Reviews > Java > convert to little endian

# convert to little endian

mike
Guest
Posts: n/a

 10-20-2004
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+=
{
lgn |= l & 0xff << shiftBy;
}
Any help would be great.

Thomas Fritsch
Guest
Posts: n/a

 10-20-2004
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+=
> {
> 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.

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

hilz
Guest
Posts: n/a

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

nice!

Thomas G. Marshall
Guest
Posts: n/a

 10-21-2004
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/