22-06-08 | 10์ง„์ˆ˜ ๐Ÿ‘‰ 2์ง„์ˆ˜ ๋ณ€ํ™˜

Moon Heeยท2022๋…„ 6์›” 8์ผ
0

// 10์ง„์ˆ˜ -> 2์ง„์ˆ˜ ๋ณ€ํ™˜

let dec = 160;
let arrBi = [];

while (dec) {
    arrBi.push(dec % 2);
    dec = Math.floor(dec / 2);
}

console.log(arrBi.reverse().join(''));

// 10์ง„์ˆ˜ -> 2์ง„์ˆ˜ ๋ณ€ํ™˜ (2๋ฒˆ์งธ ๋ฐฉ๋ฒ•)

let dec = 160;

console.log(dec.toString(2));

์ฒซ๋ฒˆ์งธ ๋ฐฉ๋ฒ•๊ณผ ๋‘๋ฒˆ์งธ ๋ฐฉ๋ฒ• ๋”ฐ๋กœ๋”ฐ๋กœ ์ฝ˜์†”์— ์ž…๋ ฅํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค!

profile
ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœํ•˜๋Š” ์‚ฌ๋žŒ

0๊ฐœ์˜ ๋Œ“๊ธ€