The Self-Taught Computer Scientist


system is a writing system for expressing numbers. In base 2, numbers have only two digits: 0 and  1. In binary, a digit is called a bit


Download 1.48 Mb.
Pdf ko'rish
bet56/147
Sana17.06.2023
Hajmi1.48 Mb.
#1540634
1   ...   52   53   54   55   56   57   58   59   ...   147
Bog'liq
books-library.net-11301817Az7X6

system is a writing system for expressing numbers. In base 2, numbers have only two digits: 0 and 
1. In binary, a digit is called a bit, which stands for binary digit. The number system you are used to 
counting in is called base 10, and it has 10 digits (zero through nine). A numeral system’s base is the 
number of digits the system has. The binary and decimal numeral systems are not the only number 
systems. There are also other numeral systems like base 16, called the 
hexadecimal system, which is 
popular with programmers.
Here are some examples of binary numbers:
100
1000
101
1101


Introduction to Algorithms
64
When you are looking at these numbers, you do not know if they are in base 2 or base 10. For 
example, the first number
100
, could be either 100 in base 10 or 4 in base 2.
There are several notations you can use to show a number is base 2. For example, computer scientists 
often put a 
b
before a number to show the number is in base 2. Here are other ways to indicate that a 
number is in base 2:
100b
1000
2
%100
0b100
place value is the numerical value a digit has because of its position in a number. For example, a 
four- digit number has place values that represent thousands, hundreds, tens, and ones. For example, the 
number 1,452 is one thousand, plus four hundreds, plus five tens, plus two ones (Figure 6.1).
In the decimal system, each place value is a power of 10. The rightmost place value is 10 to the 
zero power, which is 1. The next place value is 10 to the first power, which is 10. The next place value 
is 10 to the second power (10 × 10), which is 100. The next place value is 10 to the third power
(10 × 10 × 10), which is 1000 (Figure 6.2).
You can express the number 1,452 as an equation using its place values:
(1 * 10 ** 3) + (4 * 10 ** 2) + (5 * 10 ** 1) + (2 * 10 ** 0) = 1452
Or visualize it as follows:
1 * 10 ** 3 = 1 * 1000 = 1000 +
4 * 10 ** 2 = 4 * 100 = 400 +
5 * 10 ** 1 = 5 * 10 = 50 +
Thousands Hundreds
Tens
Ones

Download 1.48 Mb.

Do'stlaringiz bilan baham:
1   ...   52   53   54   55   56   57   58   59   ...   147




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling