StudyCatLearn / Practice / Excel
CSCI 127 Joy and Beauty of Data · Unit 1: Data types · on Exam 2

1.8 Computer memory: how values are stored

Study notes for Computer memory: how values are stored in CSCI 127 Joy and Beauty of Data at Montana State University: the big ideas, code you should know, a worked example, common mistakes and an exam tip. The same topic has endless practice questions and flashcards in StudyCat.

Big ideas

Code you should know

Names, objects and immutability
x = 5
y = x
y += 1
print(x, y, x is y)

a = "cat"
b = a
b = b + "s"
print(a, b)
print(0.1 + 0.2, 0.1 + 0.2 == 0.3, round(0.1 + 0.2, 2) == 0.3)
Output
5 6 False
cat cats
0.30000000000000004 False True
Bits, bytes and binary
print(bin(11), int("1011", 2), 2 ** 10)
print(ord("A"), chr(65), bin(ord("A")))
for n in range(0, 9):
    print(n, format(n, "04b"))
Output
0b1011 11 1024
65 A 0b1000001
0 0000
1 0001
...

Worked example

Convert binary 110101 to decimal and 45 to binary.
Show the solution
110101 = 32 + 16 + 4 + 1 = 53. 45 = 32 + 8 + 4 + 1 = 101101 (subtract the largest power of two that fits, repeat).

Common mistakes

Exam tipBe able to convert small binary numbers by hand and to explain, in one sentence, why 0.1 + 0.2 is not exactly 0.3.

Keep going in StudyCat

StudyCat is free for Montana State students: an endless quizzer with worked explanations, one-question lessons, flashcards, exam prep checklists, the class calendar with every deadline, a grade calculator and a study board for CSCI 127.