All data is stored in sequences of binary (ones and zeros), and how any binary sequence is interpreted depends on how it will be used. Binary sequences are used to represent instructions to the computer and various types of data depending on the context.
Computers store information in binary using bits and bytes. A bit is a "0" or "1". A byte is eight bits grouped together like 10001001.
As computers become more powerful, they are capable of handling more information. We used to measure computer memory in kilobytes; one kilobyte is 2^{10} (1,024) bytes, which is about 10^{3}, so we call it a "kilo". These days, your computer memory is likely to be measured in megabytes. One megabyte is 2^{20} (about 1 million) bytes.
Your hard drive space is likely to be measured in gigabytes, terabytes, or even petabytes. One gigabyte is 2^{30} (about 1 billion) bytes, one terabyte is 2^{40} (about 1 trillion) bytes, and one petabyte is 2^{50} (about 1 quadrillion) bytes.
measure | amount | example |
bit | either a 1 or a 0 | 1 |
byte | 8 bits | 11011001 |
kilobyte | 2^{10} (1,024) bytes | a couple of paragraphs |
megabyte | 2^{20} (1,048,576) bytes | about 1 book |
gigabyte | 2^{30} (1,073,741,824) bytes | a little more than 1 CD |
terabyte | 2^{40} (1,099,511,627,776) bytes | about 1,500 CDs |
petabyte | 2^{50} (1,125,899,906,842,624) bytes | about 20 million filing cabinets of text |
Depending on the programming language used, an integer might be stored with two or perhaps four bytes of data allowing for a range of about -32,768 to 32,767 (with two bytes) or -2,147,483,648 to 2,147,483,647 (with four bytes).
Two bytes is 16 bits, so two bytes can represent 2^{16} = 65,536 different values. We use about half of these to represent negative numbers, about half for postive numbers, and one to represent zero.
Four bytes is 32 bits, so four bytes can represent 2^{32} = 4,294,967,296 different values. Again, we use about half for negative numbers, half for postives, and one for zero.
What's going on? Although 200! is very large, it's not infinite. This report is the result of the size limitation. If the result of a computation is bigger than than the range of numbers that can be stored, then the computer returns a special code or an overflow error.
It's common for programming languages to use a specific number of bits to represent Unicode characters or integers. Unicode is a system that allows computers to store letters as integers. For example, capital A is Unicode number 65, which is 01000001_{2}.
Many languages have another data type used to represent real numbers (including decimals and numbers too big to be stored as integers) called floating point, which is essentially a binary version of scientific notation. It's called floating point because the decimal point "floats" to just after the first digit.
That e+32
is just a different way to write scientific notation. The "e+" means "times ten to the power of" so: 2.6525285981219103\text{e}+32 = 2.6525285981219103\times10^{32} =265,252,859,812,191,030,000,000,000,000,000.
Most real numbers can't be represented exactly—even with floating point.
The decimal representation of \frac13 is 0.33333... It has infinitely many digits, so the closest you can come in floating point isn't exactly \frac13; it gets cut off after a while.
Roundoff errors can result in some pretty weird calculations...
This isn't a bug with Snap!. Many other languages (like JavaScript) will report the same values for these calculations.
Computer arithmetic on integers is straightforward. Either you get an exactly correct integer result or, if the result won't fit in integer representation, you get an overflow error and the result is, usually, converted to floating point representation (like 30! was).
By contrast, computer arithmetic on floating point numbers is hard to get exactly right. Prior to 1985, every model of computer had a slightly different floating point format, and all of them got wrong answers to certain problems. This situation was resolved by the IEEE 754 floating point standard, which is now used by every computer manufacturer and has been improved several times since it was created in 1985.
How does a programming language know whether to interpret a bit sequence as an integer, a floating point, a text string of Unicode characters, an instruction, or something else? Programming languages differ in how they do this, but there's always some extra bit sequence that encodes the data type of any sequence of bits that tells the computer how to interpret it.
false
and 1 for true
.