int deci = 10; // deci == 10 (base 10)
int hex = 0xFB25; // hex == 64293 (base 10)
int oct = 0127; // oct == 87 (base 10)
int bin = 0b10111000; // bin == 184 (base 10)
0b0101 << 1 == 0b1010
0b1010 >> 1 == 0b0101
0xF0000000 >>> 4 == 0x0F000000
0b1100 & 0b0101 == 0b0100
0b1100 | 0b0101 == 0b1101
0b1100 ^ 0b0101 == 0b1001
0xFF00FF00 == 0x00FF00FF
For example, this code:
int a = -5; int b = 6; int c = -10; int absSum = 0; if( a < 0 ){ absSum += -a; } else { absSum += a; } if( b < 0 ){ absSum += -b; } else { absSum += b; } if( c < 0 ){ absSum += -c; } else { absSum += c; } |
can be written as this code:
int a = -5; int b = 6; int c = -10; int absSum = ( a < 0 ? -a : a) + (b < 0 ? -b : b)+ (c < 0 ? -c : c); |
// This converts an int (decimal value) to a String representing the binary value
public static String toBinaryString( int decimalNumber ){ }
// This converts an int (decimal value) to a String representing the hexadecimal value.
public static String toHexString( int decimalNumber ){ }
// This converts a String representing a hexadecimal value to an int (decimal value)
public static int parseHexString( String hexString ){ }
// This converts a String representing a binary value to an int (decimal value)
public static int parseBinaryString( String binaryString ){ }