convert to little endian

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

  1. mike

    mike Guest

    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
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

  3. mike

    hilz Guest

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

    nice!
     
    hilz, Oct 20, 2004
    #3
  4. 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
    #4
    1. Advertising

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.
Similar Threads
  1. hicham
    Replies:
    2
    Views:
    9,078
    dxcoder
    Jul 2, 2003
  2. Ernst Murnleitner

    float: IEEE, big endian, little endian

    Ernst Murnleitner, Jan 13, 2004, in forum: C++
    Replies:
    0
    Views:
    904
    Ernst Murnleitner
    Jan 13, 2004
  3. invincible

    Little Endian to Big Endian

    invincible, Jun 14, 2005, in forum: C++
    Replies:
    9
    Views:
    14,410
    Old Wolf
    Jun 14, 2005
  4. invincible
    Replies:
    1
    Views:
    563
    red floyd
    Jun 14, 2005
  5. hicham

    convert from big-endian to little-endian

    hicham, Jun 30, 2003, in forum: C Programming
    Replies:
    0
    Views:
    1,557
    hicham
    Jun 30, 2003
Loading...

Share This Page