Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

getting an int from a byte[] ?

Options
  • 23-02-2004 9:08pm
    #1
    Registered Users 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 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