Samual Sam has Published 2492 Articles

Java Program to implement NOT operation on BigInteger

Samual Sam

Samual Sam

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

90 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

76 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

216 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

421 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

1K+ 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

381 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

Divide one BigInteger from another BigInteger in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:25:27

101 Views

Use the BigInteger divide() method in Java to divide one BigInteger from another.First, let us create some objects.BigInteger one, two, three; one = new BigInteger("200"); two = new BigInteger("100");Divide the above and assign it to the third object −three = one.divide(two);The following is an example −Example Live Demoimport java.math.*; public class ... Read More

Calculate the power on a BigInteger in Java

Samual Sam

Samual Sam

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

173 Views

Use the BigInteger pow() method in Java to calculate the power on a BigInteger.First, let us create some objects.BigInteger one, two; one = new BigInteger("5");Perform the power operation and assign it to the second object −// power operation two = one.pow(3);The following is an example −Example Live Demoimport java.math.*; public class ... Read More

Shift right in a BigInteger in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:22:00

150 Views

To shift right in a BigInteger, use the shiftRight() method.The java.math.BigInteger.shiftRight(int n) returns a BigInteger whose value is (this >> n). Sign extension is performed. The shift distance, n, may be negative, in which case this method performs a left shift. It computes floor(this / 2n).The following is an example ... Read More

Enum for days of week in Java

Samual Sam

Samual Sam

Updated on 29-Jun-2020 05:19:04

2K+ Views

To set enum for days of the week, set them as constantsenum Days { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday }Now create objects and set the above constants −Days today = Days.Wednesday; Days holiday = Days.Sunday;The following is an example −Example Live Demopublic class Demo {    enum Days { ... Read More

Advertisements