Convert Decimal to Hexadecimal in Java

Samual Sam
Updated on 26-Jun-2020 10:50:01

6K+ Views

To convert decimal to hexadecimal, use any of the two methods i.e.Integer.toHexString() − It returns a string representation of the integer argument as an unsigned integer in base 16.Integer.parseInt() − It allows you to set the radix as well, for example, for hexadecimal set it as 16.Let us see an example now to convert decimal to hexadecimal using Integer.toHexString() method.Example Live Demopublic class Demo {    public static void main( String args[] ) {       int dec = 158;       System.out.println(Integer.toHexString(dec));    } }Output9eLet us see an example now to convert decimal to hexadecimal using Integer.parseInt() method.Example Live ... Read More

Convert String to a Number in Java

Samual Sam
Updated on 26-Jun-2020 10:49:12

2K+ Views

To convert a string to a number in Java, use the Integer.parseInt() method. First, let use create a String and set value.String str = "45";Now, take an Integer and use the Integer.parseInt() method.Integer i = Integer.parseInt(str);Let us see the complete example.Example Live Demopublic class Demo {    public static void main( String args[] ) {       String str = "45";       Integer i = Integer.parseInt(str);       System.out.println("Num: " + i);    } }OutputNum: 45

Convert Boolean Value to Boolean in Java

Samual Sam
Updated on 26-Jun-2020 10:48:25

5K+ Views

Use the valueOf() method to convert boolean value to Boolean. Firstly, let us take a boolean value.boolean val = false;Now, to convert it to Boolean object, use the valueOf() method.Boolean res = Boolean.valueOf(val);Let us now see the complete example to convert boolean value to Boolean.Example Live Demopublic class Demo {    public static void main(String[] args) {       boolean val = false;       System.out.println("Boolean Value = "+val);       Boolean res = Boolean.valueOf(val);       System.out.println("Boolean = " + res);       if (res.equals(Boolean.TRUE)) {          System.out.println("Boolean = " + res); ... Read More

Create Boolean Variable from String in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:47:48

327 Views

Use the parseBoolean() method to create a boolean variable from a string. Here for boolean variable, firstly take a boolean and pass the string to it using Boolean.parseBoolean().boolean val1 = Boolean.parseBoolean("TRUE");The parseBoolean() parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".Do the same for FALSE as well.boolean val2 = Boolean.parseBoolean("FALSE");Let us now see the complete example to form a boolean variable from string.Example Live Demopublic class Demo {    public static void main(String[] args) {       boolean val1 ... Read More

Convert Integer to Boolean in Java with Specified Values

Samual Sam
Updated on 26-Jun-2020 10:47:23

254 Views

To convert an Integer to a boolean, we have taken the following Integer objects.Integer one = 1; Integer two = 1; Integer three = 0;We have taken nested if-else statement to display the true or false values. Here, the value “one” is the same as “two” i.e. 1; therefore, the following else-if works.else if (one.equals(two)) {    System.out.println(true); }The above display “true” and in this way we converted Integer to boolean.Let us now see the complete example to learn how to convert an Integer to Boolean.Example Live Demopublic class Demo {    public static void main(String[] args) {       ... Read More

Parse and Format a Number to Octal in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:46:33

754 Views

To parse and format a number to octal, try the following code −Example Live Demopublic class Demo {    public static void main( String args[] ) {       int val = Integer.parseInt("150", 8);       System.out.println(val);       String str = Integer.toString(val, 8);       System.out.println(str);    } }Output104 150In the above program, we have used the Integer.parseInt() and Integer.toString() method to convert a number to octal.int val = Integer.parseInt("150", 8); String str = Integer.toString(val, 8);The toString() method above represents a value in string and formats.We have set the radix as 8, since octal is represented by radix 8.

Underflow of Datatypes in Java

Samual Sam
Updated on 26-Jun-2020 10:46:06

304 Views

Underflow occurs when the given value is less than the maximum prescribed size of a data type. The underflow condition can result to an error or now the implementation of the programming language handles it on its own.To display underflow of datatypes, I have taken an example of double datatype. Double data type is a single-precision 64-bit IEEE 754 floating point.The following program display underflow of datatype in Java.Example Live Demopublic class Demo {    public static void main(String[] args) {       System.out.println("Displaying Underflow... ");       double val1 = 3.2187E-320;       System.out.println(val1/1000000);    } }OutputDisplaying ... Read More

Random Number Generator in Java

karthikeya Boyini
Updated on 26-Jun-2020 10:45:38

3K+ Views

To generate random numbers in Java, use.import java.util.Random;Now, take Random class and create an object.Random num = new Random();Now, in a loop, use the nextInt() method since it is used to get the next random integer value. You can also set a range, like for 0 to 20, write it as.nextInt( 20 );Let us see the complete example wherein the range is 1 to 10.Example Live Demoimport java.util.Random; public class Demo {    public static void main( String args[] ) {       Random num = new Random();       int res;       for ( int i = 1; i

Integer equals() Method in Java

Samual Sam
Updated on 26-Jun-2020 10:45:13

10K+ Views

The Equals() method compares this object to the specified object. The result is true if and only if the argument is not null and is an Integer object that contains the same int value as this object.Let us first set Integer object.Integer val1 = new Integer(30); Integer val2 = new Integer(60); Integer val3 = new Integer(55); Integer val4 = new Integer(30);Now let us check their equality using the Equals() method.val1.equals(val2);In the same way, check it for different Integers.Let us see the complete example.Example Live Demoimport java.util.Random; public class Demo {    public static void main( String args[] ) {     ... Read More

8085 Program to Subtract Two 8-Bit Numbers

Chandu yadav
Updated on 26-Jun-2020 10:44:57

23K+ Views

In this program, we will see how to subtract two 8-bit numbers using 8085 microprocessor.Problem StatementWrite 8085 Assembly language program to subtract two 8-bit numbers and store the result at locations 8050H and 8051H.DiscussionIn 8085, the SUB instruction is used 2’s complemented method for subtraction. When the first operand is larger, the result will be positive. It will not enable the carry flag after completing the subtraction. When the result is negative, then the result will be in 2’s complemented form and carry flag will be enabled. We are using two numbers at location 8000H and 8001H. When the numbers are ... Read More

Advertisements