I have this small code :
public static void main(String[] args) {
byte[] bytesArray = {7,34};
BigInteger bytesTointeger= new BigInteger(bytesArray);
System.out.println(bytesTointeger);
}
Output:1826
My question is what just happened how an array of bytes {7,34} converted into this number 1826 , what is the operation that caused this result ? like how to convert it manually
BigInteger class provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations. BigInteger bInteger = new BigInteger(arr); The following is an example that creates BigInteger from a byte array in Java.
Convert byte[] array to File using Java In order to convert a byte array to a file, we will be using a method named the getBytes() method of String class. Implementation: Convert a String into a byte array and write it in a file.
The intValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as int.
The number 1826 is, in binary, 11100100010
.
If you split that in groups of 8 bits, you get the following:
00000111 00100010
Which are the numbers 7 and 34
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With