Hexadecimal said

Kotlin does not support representation in base 8.

  • binary
0b1101
Copy the code
  • hexadecimal
0xd
Copy the code

operation

  • And 1001 &1101 -> 1001
(0b1001 and 0b1101).toString(2)
/ / or
0b1001.and(0b1101).toString(2)
Copy the code
  • Or 1001 | 1101 – > 1101
(0b1001 or 0b1101).toString(2)
/ / or
0b1001.or(0b1101).toString(2)
Copy the code
  • Xor 1001 ^ 1101 -> 0100
(0b1001 xor 0b1101).toString(2)
/ / or
0b1001.xor(0b1101).toString(2)
Copy the code
  • Shift left 1001 << 1 -> 10010
(0b1001 shl 1).toString(2)
/ / or
0b1001.shl(1).toString(2)
Copy the code
  • Move right 1001 >> 1 -> 0100
(0b1001 shr 1).toString(2)
/ / or
0b1001.shr(1).toString(2)
Copy the code
  • Unsigned move right 1001 >>> 1 -> 0100
(0b1001 ushr 1).toString(2)
/ / or
0b1001.ushr(1).toString(2)
Copy the code

The decimal system

  • Decimal conversion to base 2 13->1101
13.toString(2)
/ / or
Integer.toBinaryString(13)
Copy the code
  • Decimal to 8 base 13->15
13.toString(8)
/ / or
Integer.toOctalString(13)
Copy the code
  • Decimal to hexadecimal 13-> D
13.toString(16)
/ / or
Integer.toHexString(13)
Copy the code

binary

  • Conversion from base 2 to base 8 1101->13->15
// Switch to base 10 and then to base 8
"1101".toInt(2).toString(8)
Copy the code
  • Convert base 2 to base 10 1101->13
"1101".toInt(2)
/ / or
Integer.valueOf("1101".2)
Copy the code
  • Conversion from base 2 to hexadecimal 1101->13-> D
// Switch to base 10 and then to base 16
"1101".toInt(2).toString(16)
Copy the code

octal

  • Conversion from base 8 to base 2 15->13->1101
// Switch to base 10 and then base 2
"15".toInt(8).toString(2)
Copy the code
  • Base 8 to base 10 15->13
"15".toInt(8)
/ / or
Integer.valueOf("15".8)
Copy the code
  • Switch from base 8 to base 16 15->13-> D
// Switch to base 10 and then to base 16
"15".toInt(8).toString(16)
Copy the code

hexadecimal

  • Convert hexadecimal to 2-base D ->13->1101
// Switch to base 10 and then base 2
"d".toInt(16).toString(2)
Copy the code
  • Hexadecimal to 8 base D ->13->15
// Switch to base 10 and then to base 8
"d".toInt(16).toString(8)
Copy the code
  • Convert hexadecimal to hexadecimal d->13
"d".toInt(16)
/ / or
Integer.valueOf("d".16)
Copy the code