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.

Please refine your problem description! What do you want to achieve?

--
"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/

 Thread Tools

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post invincible C++ 9 06-14-2005 10:21 PM invincible C++ 1 06-14-2005 04:20 PM Ernst Murnleitner C++ 0 01-13-2004 01:48 PM hicham C++ 2 07-02-2003 04:55 PM hicham C Programming 0 06-30-2003 10:16 AM

Advertisments