반응형
10진수 > 2진수(2, 3, 4, 5,.... , N 진수)
: 2진수에서 N 진수로 변경을 하는 경우에는 아래와 같은 예시로 실행 시 문제없이 실행이 됩니다.
let decimal = 2022;
//10진수 -> 2진수
console.log(decimal.toString(2));
//10진수 -> 3진수
console.log(decimal.toString(3));
//10진수 -> N진수
console.log(decimal.toString(N));
N진수(2, 3, 4, 5, ... , N) > 10진수
: n진수법에서 10진수로 변경을 하는것 또한 parseInt 메서드를 통해서 쉽게 변환이 가능합니다.
//2진수 -> 10진수
let binary = "1011"
console.log(parseInt(number,2));
//3진수 -> 10진수
let trinary = "2122"
console.log(parseInt(number,3));
//N진수 -> 10진수
let number = "nnnn"
parseInt(number,N);
N진수> N진수
위에 내용을 토대로 만들다보면 이 모든 조합을 합쳐서 n진수에서 n진수로 변환을 하는 것 도 간단하게 가능하다.
//3진수 -> 2진수
console.log(parseInt("21121",3).toString(2));
반응형
'IT > error' 카테고리의 다른 글
[error] Uncaught TypeError: $.ajax is not a function (0) | 2025.02.28 |
---|---|
Tainted canvases may not be exported (0) | 2025.01.10 |
Uncaught RangeError: Invalid string length 오류 (0) | 2024.11.22 |
[포토샵] 스탬프 오류 : could not use the clone stamp because the area to clone has not been defined (0) | 2024.10.26 |
Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob (0) | 2024.09.13 |
댓글