Bits and binary
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Bits: the smallest piece of data
- A bit is one digit that is either
0or1. - Computers store everything — numbers, text, images — as bits.
- One bit alone is small, so we group many bits together.
한국어
비트: 가장 작은 데이터 단위
- 비트는
0또는1인 한 자리 숫자입니다. - 컴퓨터는 모든 것(숫자, 텍스트, 이미지 등)을 비트로 저장합니다.
- 단일 비트만으로는 작으므로, 여러 비트를 묶어 사용합니다.
English
Why computers use binary
- A computer chip has tiny switches. Each switch is on or off.
on=1andoff=0. So two states fit a chip perfectly.- Counting with only
0and1is called binary (base 2).
한국어
왜 컴퓨터는 이_Handle를 사용하나요
- 컴퓨터 칩에는 미세한 스위치가 있습니다. 각 스위치는 켜짐 또는 꺼짐 상태입니다.
on=1이고off=0입니다. 따라서 두 가지 상태가 칩에 완벽하게 부합합니다.0과1만으로 세는 것을 이_Handle(2진법)라고 합니다.
English
How binary counts
- Our normal numbers use base 10 (digits
0–9). - Binary uses base 2. Each place is worth twice the place on its right.
- The places are
8 4 2 1. So1101means8 + 4 + 0 + 1 = 13.
한국어
이_Handle로 세는 방법
- 우리가 일반적으로 사용하는 숫자는 10진법(자리수
0–9)을 사용합니다. - 이_Handle는 2진법을 사용합니다. 각 자리의 가치는 오른쪽 자리보다 두 배 큽니다.
- 자리는
8 4 2 1입니다. 따라서1101은8 + 4 + 0 + 1 = 13을 의미합니다.
place: 8 4 2 1
bits: 1 1 0 1 -> 8 + 4 + 0 + 1 = 13
English
Python can convert for you
bin(13)gives the string'0b1101'. The0bjust means "this is binary".int("1101", 2)reads"1101"as base 2 and gives13.- These two functions go in opposite directions.
한국어
Python이 변환을 도와줍니다
bin(13)은 문자열'0b1101'을 반환합니다.0b는 "이것은 이_Handle"라는 뜻입니다.int("1101", 2)은"1101"을 2진법으로 해석하여13을 반환합니다.- 이 두 함수는 반대 방향으로 작동합니다.
print(bin(13)) # decimal -> binary
print(int("1101", 2)) # binary -> decimal
English
Fixed bits and overflow
- A computer keeps a number in a fixed number of bits.
- With 4 bits you can store
0to15— that is2**4 = 16different values. - If a result is too big, it wraps around back to
0. This is overflow.
한국어
고정 비트와 오버플로우
- 컴퓨터는 고정된 수의 비트로 숫자를 유지합니다.
- 4비트를 사용하면
0부터15까지 저장할 수 있으며, 이는 총2**4 = 16개의 다른 값을 의미합니다. - 결과가 너무 크면 회전되어 다시
0로 돌아갑니다. 이를 오버플로우라고 합니다.
print(2 ** 4) # how many values 4 bits hold = 16
print((15 + 3) % 16) # 18 is too big, so it wraps to 2
English
Common mistakes
nbits store2**ndifferent values, from0to2**n - 1.- Binary is base 2: each place is worth twice the one to its right.
한국어
흔한 실수
n비트는2**n개의 다른 값을 저장하며, 범위는0부터2**n - 1까지입니다.- 이_Handle는 2진법입니다: 각 자리의 가치는 오른쪽 자리보다 두 배 큽니다.
English
Now you try
- Type your code below and press Run to see the output.
- Press Check answer to test it.
한국어
이제 직접 해보기
- 아래에 코드를 입력하고 실행 버튼을 눌러 출력을 확인하십시오.
- 답안 확인을 눌러 테스트해 보십시오.
Explore · 탐색하기
Binary counts in powers of 2
Each bit is a power of two; lit bits add up to the value.
Use bin(...) to print the binary form of 20. The output should look like 0b10100.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
The binary string "110" is a number. Use int(s, 2) to print it as a normal (decimal) number.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
A counter has 5 bits, so it holds 2**5 = 32 values. Store 2**5 in size. Then store (30 + 5) % size in result to show how the value wraps around (overflow).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.