Link to home
Start Free TrialLog in
Avatar of s_lavie
s_lavie

asked on

BigInteger and byte array

How I can represent the following 8 bytes in a byte[] 0x00ff000000000000 ?
In other words, I want something like:
byte[] myBytes = { 00, ff, 00, 00, 00, 00, 00, 00 };
I know 0xff is an unsigned byte and I can use char as its type, but I want to construct a BigInteger with that array.
BigInteger bi = new BigInteger(myBytes);
Any suggestions?
Avatar of yongsing
yongsing

>> BigInteger bi = new BigInteger(myBytes);

The above is ok. One of the constructors takes a byte array.

What's your problem?
Avatar of s_lavie

ASKER

> What's your problem?
initiate that array when one of the entries is 0xff
byte[] myBytes = { 0x00b, 0xffb, 0x00b, 0x00b, 0x00b, 0x00b, 0x00b, 0x00b };
ASKER CERTIFIED SOLUTION
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of s_lavie

ASKER

Does (byte)0xff can cause any harm?
no - it simply gets the lowes byte from the integer value - which is exactly what you want
Avatar of s_lavie

ASKER

Thank you all