4F7B: Binary = 100111101111011 Decimal = 20347
Decimal: 170Hex: AA
1
221122: Binary = 1000100001000100100010 Octal = 10410442 Decimal = 2232610
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(); } }
-10011093
4F7B: Binary = 100111101111011 Decimal = 20347
Decimal is base 10. Binary is base 2. Octal is base 8. Hexadecimal is base 16.
It is used because it is easier to convert to and from binary to hexadecimal than decimal, and it uses less characters than binary. For instance: decimal: 65535 hex: FFFF binary: 1111111111111111
If the above is decimal then in hexadecimal it is 2964492C2. If it is binary then in hexadecimal it is 7DA. If it is octal then in hexadecimal it is 49241208.
Decimal: 170Hex: AA
In hexadecimal, that would be 0x2E, which is equivalent to 46 in decimal, which in binary is 101110.
1
221122: Binary = 1000100001000100100010 Octal = 10410442 Decimal = 2232610
10,923 decimal 2AAB Hexadecimal 25,253 Octadecimal
111111 in binary is 255 in decimal which is FF in hexadecimal (i.e. 15 units and 15 16s)
157 as a binary number is 10011011