Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Bits and bytes through Java...

  • 24-01-2003 10:37AM
    #1
    Posts: 431 ✭✭


    Hey all,

    Could anyone please tell me how to calculate low and high bytes of a number in Java?

    For example, if I gave a parameter of say 256 (each register is 16 bits), the high byte would be

    00000001

    and the low byte

    00000000

    Using the bit shift operators, how would I calculate these values?
    I've been trying this for the last few days and it's driving me up the wall.

    Thanks for any help :)


Comments

  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭Zab


    The low byte would be

    i & 0xff

    And the high byte would be

    ( i >> 8 ) & 0xff


    Zab.


  • Posts: 431 ✭✭ [Deleted User]


    That's great, thanks for the help


Advertisement