Samual Sam has Published 2310 Articles

Parse Octal string to create BigInteger in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:48:05

178 Views

To parse the octal string to create BigInteger, use the following BigInteger constructor and set the radix as 8 for Octal −BigInteger(String val, int radix)This constructor is used to translate the String representation of a BigInteger in the specified radix into a BigInteger.In the below example, we have set the ... Read More

Parse hexadecimal string to create BigInteger in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:46:43

2K+ Views

To parse the hexadecimal string to create BigInteger, use the following BigInteger constructor and set the radix as 16 for Hexadecimal.BigInteger(String val, int radix)This constructor is used to translate the String representation of a BigInteger in the specified radix into a BigInteger.In the below example, we have set the BigInteger ... Read More

Parsing and Formatting a Big Integer into Binary in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:45:49

2K+ Views

Firstly, take two BigInteger objects and set values.BigInteger one, two; one = new BigInteger("99"); two = new BigInteger("978");Now, parse BigInteger object “two” into Binary.two = new BigInteger("1111010010", 2); String str = two.toString(2);Above, we have used the following constructor. Here, radix is set as 2 for Binary for both BigInteger constructor ... Read More

Parsing and Formatting a Byte Array into Binary in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:44:09

4K+ Views

Set a BigInteger object.BigInteger one;Now, create a ByteArray.byte byteArr[] = new byte[] { 0x1, 0x00, 0x00 }; one = new BigInteger(byteArr);For Binary, we have used 2 as the toString() method parameter.String strResult = one.toString(2);The following is an example −Example Live Demoimport java.math.*; public class Demo {    public static void main(String[] ... Read More

Java Program to implement NOT operation on BigInteger

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:38:35

142 Views

The BigInteger.not() method returns a BigInteger whose value is (~this). This method returns a negative value if and only if this BigInteger is non-negative.The following is an example −Example Live Demoimport java.math.*; public class Demo {    public static void main(String[] args) {       BigInteger one, two, three;   ... Read More

Java Program to implement andNot operation on BigInteger

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:35:51

132 Views

TheBigInteger.andNot(BigInteger val) returns a BigInteger whose value is (this & ~val). This method, which is equivalent to and(val.not()), is provided as a convenience for masking operations. This method returns a negative BigInteger if and only if this is negative and val is positive. Here, “val” is the value to be ... Read More

Left pad a String with spaces (' ') in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:33:33

329 Views

Let us see an example first to understand how a string looks with left padding −demotext //left padding with spaces 0000000demotext //left padding with 7 zerosThe following is our string −String str = "Jack";Now take a StringBuilder object −StringBuilder strBuilder = new StringBuilder();Perform left padding and extend the string length. ... Read More

Left pad a String in Java with zeros

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:30:58

580 Views

The following is our string −String str = "Tim";Now take a StringBuilder object −StringBuilder strBuilder = new StringBuilder();Perform left padding and extend the string length. We have set it till 20, that would include the current string as well. The zeros that will be padded comes on the left. Append ... Read More

Create BigInteger from byte array in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:28:41

2K+ Views

BigInteger class provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.Let’s say the following is our byte array −byte[] arr = new byte[] { 0x1, 0x00, 0x00 };We will now convert them to BigInteger −BigInteger bInteger = new BigInteger(arr);The following ... Read More

Multiply one BigInteger to another BigInteger in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:26:40

466 Views

BigInteger class is used for big integer calculations which are outside the limit of the primitive data types. It provides operations for modular arithmetic, GCD calculation, primality testing, prime generation, bit manipulation, and a few other miscellaneous operations.To multiply one BigInteger to another, use the BigInteger multiply() method.First, let us ... Read More

Advertisements