개발입문/JAVA

[30일코딩] Binary Numbers 2진법

haloaround 2017. 5. 6. 18:15

Base 2, 2진법의 세계


컴퓨터의 세계는 0과 1, 

- Booleans : True or False 

- ON / OFF Switch

- 1 bit 



사람은 Base 10 10진법,  달력은 12진법을 사용합니다.

용도에 따라 10진법 수을 2진법으로, 12진법으로 자유자재로 변경할 수 있어야 합니다~

- Binary to Decimal Conversion

- Decimal to Binary Conversion




Base 진법의 원리


A * B^D

A: 0 ~  Base -1

B: Base

D: Numerical Digit Location


e.g. 723 = 7 * 10^2 + 2 * 10^1 + 3 * 10^0




2진법 유사코드


while(n > 0):

    remainder = n%2;

    n = n/2;

    Insert remainder to front of a list or push onto a stack


Print list or stack