Hmm, thought I did the same thing using the codec lib. Of course, my
brain is %90 malted hops and bong resin; so thanks for correcting me.
- Ryan
> > There is a commons library that makes conversion very easy:
> >
[quoted text clipped - 4 lines]
> A simple cast is all that's required, as already posted, but the '&
> 0xff' is not required. The cast does that already.
> A simple cast is all that's required, as already posted, but the '&
> 0xff' is not required. The cast does that already.
It *is* required if you want the output be between 0 and 255.
sgoo - 26 Nov 2006 15:28 GMT
Sorry, I thought it was from byte->int. It's not necessary here.
> > A simple cast is all that's required, as already posted, but the '&
> > 0xff' is not required. The cast does that already.It *is* required if you want the output be between 0 and 255.
Chris Uppal - 26 Nov 2006 15:43 GMT
> > A simple cast is all that's required, as already posted, but the '&
> > 0xff' is not required. The cast does that already.
>
> It *is* required if you want the output be between 0 and 255.
Depends on whether you want to mask an integer value down to a byte value, i.e.
a value between 0 and 255 inclusive; or whether you want to put the resulting
value into a Java byte variable (or array slot) which holds values in the
range -128 to +127 inclusive. In the former case you should mask with 0xFF
(but don't cast, leave the result as an int); in the later case you just cast
(masking will gain exactly nothing).
-- chris