이 페이지는 최신 브라우저(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.
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).
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.
English
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.
English
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 for the bits, that is an overflow error. Some languages keep only the bits that fit, so the value wraps around: with 4 bits,
15 + 3becomes2.
English
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.
English
Now you try
- Type your code below and press Run to see the output.
- Press Check answer to test it.
탐색하기
이_Handle수는 2의 거듭제곱으로 세는 법
각 비트는 2의 거듭제곱; 켜진 비트들의 합이 해당 값입니다.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
20의 이_Handle수 형식을printed하려면 bin(...)을 사용하십시오. 출력은 0b10100과 같이 보여야 합니다.
출력을 보려면 '실행'을 클릭하세요.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
이진 문자열 "110"은 숫자입니다. int(s, 2)을 사용하여 이를 일반(진법) 숫자로 출력하십시오.
출력을 보려면 '실행'을 클릭하세요.
난이도 1/5 · 100코인 + 오늘 첫 완료 시 작은 보너스 추가
카운터에는 5비트가 있어 2**5 = 32개의 값을 가질 수 있습니다. 2**5을 size에 저장한 후, 값이 wrap-around(오버플로우)되는 방법을 보여주기 위해 (30 + 5) % size을 result에 저장하십시오.
출력을 보려면 '실행'을 클릭하세요.