This is the 19th day of my participation in the August Wenwen Challenge.More challenges in August
This article is mainly about basic computer data storage mode, the article translated from Stanford university courses: web.stanford.edu/class/cs101…
Bits and Bytes
The smallest units in which a computer stores data are bits and bytes. Let’s look at how bits and bytes encode information.
Bits (digits)
A bit is the atomic, indivisible, smallest unit of storage
Bits store only zeros or ones
“In a computer, it’s all zeros and ones.
8 bits = 1 byte
Everything in a computer is 0 and 1, and bits store only 0 or 1, the smallest place of storage
Byte (Byte)
1 byte = 8 bits
For example, 01011010
A byte can store one character, such as ‘A’, ‘x’, ‘$’
How many ways can N bits be combined?
How many ways can bits 1, 2 and 3 be combined?
Number of bits | Different Patterns |
---|---|
1 | 0 1 |
2 | 00 01 October 11 |
3 | 000 001 010 011 100 101 110 111 |
And we can see that there are only two choices for a 1 bit: 0 or 1
For 2 bits, let’s fix the left bit, so for 0 we have 00 and 01, and for 1 we have 10 and 11, so in this case 2 times 2 is 4
Three digits and similarly, if we fix the first two digits, we have four choices, two choices for each of the first two digits, so 4 times 2 is 8
By analogy, 4 bits is 8*2=16, so we can get:
- 1:2
- 2 a: 4
- Three: 8
- 4:16
- Five: 32
- A: 64
- 7 a: 128
- 8 bits: 256 (one byte)
So you can see that there are 2 to the n bits in 2 to the n
There are 256 ways to combine a byte
A byte consists of eight bits
Eight bits can produce 256 combination modes
So how do you use these 256 combinations?
How do I store a number in a byte?
Counting upward from 0, each number corresponds to a pattern until the pattern is used up
0, 1, 2, 3, 4, 5… 254, 255,
A byte can hold numbers between 0 and 255
With 256 different modes, we can store numbers between 0 and 255
Great for storing characters/letters
Bytes (Bytes)
Byte – A unit of information storage
How many bytes does a document, a picture, a movie contain?
A byte is enough to hold one typed character, such as ‘A’, ‘x’, ‘$’
Although hardware varies greatly, all storage is in byte bits
Bytes and Characters – ASCII Code (Bytes and Characters – ASCII Code)
ASCII is the numeric encoding of each typed character
Each number is stored in one byte, so the number ranges from 0 to 255
- A is 65
- B is 66
- A is 97
- Space is 32
Unicode is the code for mandarin, Greek, Arabic and other languages, and each “character” is usually represented by two bytes
Typing, Bytes, and You (Typing, Bytes and You)
As mentioned above, each letter is stored in a byte
100 typed letters take up 100 bytes
Text is very compact and takes up very few bytes compared to images and so on
Numbers in a computer
A byte can handle a single character very well, but computers are also very good at handling numbers
Integers are usually stored in 4-8 bytes
Four bytes can store numbers in the range of -2147483648 to 2147483647. Eight bytes can store numbers in the range of -9223372036854775808 to 9223372036854775807
Binary addition is just like ordinary addition with carry
The leftmost bits represent signs, so the bits that move to the leftmost will change from positive to negative
Integer Overflow and Gangam Style
That’s the basic concept of the smallest unit of data a computer can store, bits and bytes
Reference:
- Web.stanford.edu/class/cs101…