다른 진법들


2진법 binary

[
  0b1,
  0b10,
  0b11,
  0b100,
  0b101
].forEach(i => console.log(i))

8진법 octal

[
  0o7,
  0o10,
  0o100,
  0o1000,
].forEach(i => console.log(i))

16진법 hexadecimal

[
  0x9,
  0xA,
  0xB,
  0xC,
  0xd,
  0xe,
  0xf,
  0x10,
  0xFFFFFF
].forEach(i => console.log(i))

진법 간 표현

const num = 123456789;

const binStr = num.toString(2);
const octStr = num.toString(8);
const hexStr = num.toString(16);

console.log(binStr, octStr, hexStr);

image.png

console.log(
  parseInt(binStr, 2),
  parseInt(octStr, 8),
  parseInt(hexStr, 16)
);

비트 연산자들