Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How BigInteger convert a byte array to number in Java?

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

like image 625
Zizoo Avatar asked Apr 01 '16 12:04

Zizoo


People also ask

How do I create an array of BigInteger in Java?

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.

Can we convert byte array to file 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.

Can we convert byte to int in Java?

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.


1 Answers

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

like image 105
Pablo Lozano Avatar answered Nov 15 '22 03:11

Pablo Lozano