?
Solved

BigInteger and byte array

Posted on 2003-03-13
7
Medium Priority
?
1,082 Views
Last Modified: 2011-04-14
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?
0
Comment
Question by:s_lavie
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Expert Comment

by:yongsing
ID: 8126722
>> BigInteger bi = new BigInteger(myBytes);

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

What's your problem?
0
 
LVL 2

Author Comment

by:s_lavie
ID: 8126931
> What's your problem?
initiate that array when one of the entries is 0xff
0
 
LVL 9

Expert Comment

by:Venci75
ID: 8126946
byte[] myBytes = { 0x00b, 0xffb, 0x00b, 0x00b, 0x00b, 0x00b, 0x00b, 0x00b };
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 16

Accepted Solution

by:
Peter Kwan earned 200 total points
ID: 8126983
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
 
LVL 2

Author Comment

by:s_lavie
ID: 8127137
Does (byte)0xff can cause any harm?
0
 
LVL 9

Expert Comment

by:Venci75
ID: 8127156
no - it simply gets the lowes byte from the integer value - which is exactly what you want
0
 
LVL 2

Author Comment

by:s_lavie
ID: 8127201
Thank you all
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question