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?
LVL 2
s_lavieAsked:
Who is Participating?
 
Peter KwanConnect With a Mentor Commented:
I have tried Venci75's comment, and still getting possible loss of precision compilation error.

I think one way is to explicit casting to byte:
byte[] myBytes =  { 0x00, (byte)0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
0
 
yongsingCommented:
>> BigInteger bi = new BigInteger(myBytes);

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

What's your problem?
0
 
s_lavieAuthor Commented:
> What's your problem?
initiate that array when one of the entries is 0xff
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Venci75Commented:
byte[] myBytes = { 0x00b, 0xffb, 0x00b, 0x00b, 0x00b, 0x00b, 0x00b, 0x00b };
0
 
s_lavieAuthor Commented:
Does (byte)0xff can cause any harm?
0
 
Venci75Commented:
no - it simply gets the lowes byte from the integer value - which is exactly what you want
0
 
s_lavieAuthor Commented:
Thank you all
0
All Courses

From novice to tech pro — start learning today.