D = 13
Chat with our AI personalities
D7 = 11010111
"The hexadecimal code of ABCDEF" is rather difficult to make. If you want the DECIMAL code for the HEXADECIMAL numbers A, B, C, D, E and F, then you get this explanation: Hexadecimal means 16 and if you are counting hexadecimal and you will start to count from 0 to 9 normally. Then you get A for 10, B for 11, C for 12 D for 13 E for 14 and F for 15.
The base in a hexadecimal system is 16. The symbols are: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
The numbers used are 0, 1, 2, ... , 15. However, the numbers 10 to 15 are denoted by A, B, C, D, E and F. This is to distinguish between, for example, the decimal 11 and the hex 11. The latter is 1*161 + 1 (in decimal) or 17 (in decimal).
import java.util.Scanner; public class NumberSystem { public void displayConversion() { Scanner input = new Scanner(System.in); System.out.printf("%-20s%-20s%-20s%-20s\n", "Decimal", "Binary", "Octal", "Hexadecimal"); for ( int i = 1; i <= 256; i++ ) { String binary = Integer.toBinaryString(i); String octal = Integer.toOctalString(i); String hexadecimal = Integer.toHexString(i); System.out.format("%-20d%-20s%-20s%-20s\n", i, binary, octal, hexadecimal); } } // returns a string representation of the decimal number in binary public String toBinaryString( int dec ) { String binary = " "; while (dec >= 1 ) { int value = dec % 2; binary = value + binary; dec /= 2; } return binary; } //returns a string representation of the number in octal public String toOctalString( int dec ) { String octal = " "; while ( dec >= 1 ) { int value = dec % 8; octal = value + octal; dec /= 8; } return octal; } public String toHexString( int dec ) { String hexadecimal = " "; while ( dec >= 1 ) { int value = dec % 16; switch (value) { case 10: hexadecimal = "A" + hexadecimal; break; case 11: hexadecimal = "B" + hexadecimal; break; case 12: hexadecimal = "C" + hexadecimal; break; case 13: hexadecimal = "D" + hexadecimal; break; case 14: hexadecimal = "E" + hexadecimal; break; case 15: hexadecimal = "F" + hexadecimal; break; default: hexadecimal = value + hexadecimal; break; } dec /= 16; } return hexadecimal; } public static void main( String args[]) { NumberSystem apps = new NumberSystem(); apps.displayConversion(); } }