Computer science fundamentals · Lesson 39 of 60 · Concept lesson · Optional
Binary and number systems
Computers store everything as bits, which are 0s and 1s.
Binary is base 2, where each place is worth twice the one to its right, while decimal is base 10 and hexadecimal is base 16.
Eight bits make a byte, which can hold 256 different values.
Picture it
Code example
console.log((11).toString(2));
console.log(parseInt("1011", 2));Output:
1011 11
toString(2) writes a number in binary, and parseInt with base 2 reads binary back.
print(format(11, "b"))
print(int("1011", 2))Output:
1011 11
format(..., "b") writes a number in binary, and int with base 2 reads binary back.
Check yourself
Pick an answer for each question. You can retry as many times as you like.
Loading the questions…