Skip to main content

Posts

Showing posts with the label Hexadecimal

Decimal to Hexadecimal Conversion code in java

 Decimal to Hexadecimal Conversion Code:: import java.util.*; import java.lang.*; import java.io.*; class Test{ public static void main(String[] args){ Scanner scn = new Scanner(System.in); int dec = scn.nextInt(); hexa(dec); } public static void hexa(int dec){ String hexa = "0123456789ABCDEF"; String res = ""; while(dec!=0){ int r = dec%16; res = hexa.charAt(r) + res; dec = dec/16; } System.out.println(res); } } ex:: hexadecimal Number :: F Decimal Number :: 15 hexadecimal number : 1A decimal number : 26

decimal to binary , decimal to octal , decimal to hexadeciaml conversions and vice versa programs in java

 binary to decimal conversion code: import java.util.*; import java.lang.*; import java.io.*; //binary to decimal class Test { public static void main(String[] args){ Scanner scn = new Scanner(System.in); //take the binary number from the user int bin = scn.nextInt(); //write the lgic to convert it into decimal int dec = 0; int i = 0;//digit place while(bin!=0){ //last digit int r = bin%10; //multiple remaider with 2 power digit place dec = dec +(r* (int)Math.pow(2,i)); //increment the position of i i++; //remove the last digit from the number bin = bin/10; } //print the decimal number System.out.println(dec); } } ex:: input : 1010 o/p: 10 input : 1000 o/p: 8 octal to decimal Conversion Code:: import java.util.*; import java.lang.*; import java.io.*; //binary to decimal class Test { public static void main(String[] args){ Scanner scn = new Scanner(System.in); //take the octal number from the user int oct = scn