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.

getting an int from a byte[] ?

  • 23-02-2004 08:08PM
    #1
    Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭


    Is there an easy way to do this?

    I have a byte[] made up of 3 ints. How do I pull the ints from it?

    This is in Java btw.


Comments

  • Registered Users, Registered Users 2 Posts: 1,481 ✭✭✭satchmo


    Do you mean you have one integer made up of 24 bits, arranged in an array? In this case it's pretty simple, use BigInteger(byteArray).intValue()... as long as the integer isn't too big for an int type, in that case just leave it as a BigInteger. And you might want to make sure they're encoded as twos-complement first.

    Or do you mean you want to convert 3 bytes into individual ints? (just a cast, I'm sure you would've done that already yourself so I guess thats not it).

    Sorry, I'm not quite sure I understand what you're trying to do, you're not your normal verbose self! :p


Advertisement