\[\sum_{i=0}^n q^i = \frac{q^{n+1}-1}{q-1}\]
\[ \sum_{i=0}^n P^i = \frac{P^{n+1}-1}{P-1},\]
\[ | X_1 - X_2 | = | \sum_{i=0}^{k} (a_i-b_i) P^i |\]
\[ | X_1 - X_2 | \geq |a_k-b_k| P^k - \sum_{i=0}^{k-1} |a_i-b_i| P^i\]
\[ | X_1 - X_2 | \geq \underset{\geq 1}{\underbrace{|a_k-b_k|}} P^k - \sum_{i=0}^{k-1} \underset{\leq P-1}{\underbrace{|a_i-b_i|}} P^i\]
\[ | X_1 - X_2 | \geq 1 P^k - \sum_{i=0}^{k-1} (P-1) P^i\]
\[ | X_1 - X_2 | \geq P^k - (P-1) \sum_{i=0}^{k-1} P^i\]
\[ | X_1 - X_2 | \geq P^k - (P-1) \frac{P^k - 1}{P-1}\]
\[ | X_1 - X_2 | \geq P^k - ({P^k - 1})\]
\[ | X_1 - X_2 | \geq 1\]
\[ | X_1 - X_2 | \geq 1\]
Рассмотрим два числа, \[ X_1 = \sum_{i=0}^n a_i P^i, \] \[ X_2 = \sum_{i=0}^m b_i P^i \]
\[ Y = X_1 + X_2, \] \[ Y = \sum_{i=0}^{\mathrm{max}(m,n)} (a_i+b_i) P^i = \sum_{i=0}^{p} c_i P^i \]
\[ Y = \ldots + (a_{i+1} + b_{i+1}) P^{i+1} \\ + (a_i+b_i) P^i + \ldots,\]
\[ Y = \ldots + (a_{i+1} + b_{i+1}) P^{i+1} \\ + (a_i+b_i-P+P) P^i + \ldots,\]
\[ Y = \ldots + (a_{i+1} + b_{i+1}) P^{i+1} + P^{i+1} \\ + (a_i+b_i-P) P^i + \ldots,\]
\[ Y = \ldots + (a_{i+1} + b_{i+1}+1) P^{i+1} \\ + (a_i+b_i-P) P^i + \ldots,\]
0 | 1 | |
---|---|---|
0 | 0 | 1 |
1 | 1 | 10 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 10 |
2 | 2 | 3 | 4 | 5 | 6 | 7 | 10 | 11 |
3 | 3 | 4 | 5 | 6 | 7 | 10 | 11 | 12 |
4 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 |
5 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 |
6 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 |
7 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
1 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 |
2 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 | 11 |
3 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 | 11 | 12 |
4 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 | 11 | 12 | 13 |
5 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 | 11 | 12 | 13 | 14 |
6 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 |
7 | 7 | 8 | 9 | A | B | C | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
8 | 8 | 9 | A | B | C | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
9 | 9 | A | B | C | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
A | A | B | C | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
B | B | C | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A |
C | C | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B |
D | D | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B | 1C |
E | E | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B | 1C | 1D |
F | F | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B | 1C | 1D | 1E |
Пример:
\(\begin{matrix} & A & 4 & D & {}_{16} \\ + & & 8 & C & {}_{16} \\ \hline{} &&&&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & A & 4 & D & {}_{16} \\ + & & 8 & C & {}_{16} \\ \hline{} &&\overset{1}{}&9&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & A & 4 & D & {}_{16} \\ + & & 8 & C & {}_{16} \\ \hline{} &&\overset{1}{C}&9&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & A & 4 & D & {}_{16} \\ + & & 8 & C & {}_{16} \\ \hline{} &A&\overset{1}{C}&9&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & A & 4 & D & {}_{16} \\ + & & 8 & C & {}_{16} \\ \hline{} &A&\overset{1}{C}&9&{}_{16} \\ \hline{} &A&D&9&{}_{16} \end{matrix}\qquad\)
\[ Y = X_1 \cdot X_2, \]
\[ Y = \left(\sum_{i=0}^n a_i P^i\right) \cdot \left(\sum_{i=0}^m b_i P^i\right) \]
\[ Y = \sum_{i=0}^m b_i P^i \left(\sum_{j=0}^n a_j P^j\right) \]
\[ Y = \sum_{i=0}^m b_i \left(\sum_{j=0}^n a_j P^{j+i}\right) \]
Рассмотрим теперь умножение на один разряд:
\[ Y_i = b_i \cdot \sum_{j=0}^n a_j P^j = \sum_{j=0}^k c_j P^j .\]
\[ Y_i = \sum_{j=0}^n a_j b_i P^j = \sum_{j=0}^k c_j P^j .\]
два варианта:
0 | 1 | |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | |
---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
2 | 0 | 2 | 4 | 6 | 10 | 12 | 14 | 16 |
3 | 0 | 3 | 6 | 11 | 14 | 17 | 22 | 25 |
4 | 0 | 4 | 10 | 14 | 20 | 24 | 30 | 34 |
5 | 0 | 5 | 12 | 17 | 24 | 31 | 36 | 43 |
6 | 0 | 6 | 14 | 22 | 30 | 36 | 44 | 52 |
7 | 0 | 7 | 16 | 25 | 34 | 43 | 52 | 61 |
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
2 | 0 | 2 | 4 | 6 | 8 | A | C | E | 10 | 12 | 14 | 16 | 18 | 1A | 1C | 1E |
3 | 0 | 3 | 6 | 9 | C | F | 12 | 15 | 18 | 1B | 1E | 21 | 24 | 27 | 2A | 2D |
4 | 0 | 4 | 8 | C | 10 | 14 | 18 | 1C | 20 | 24 | 28 | 2C | 30 | 34 | 38 | 3C |
5 | 0 | 5 | A | F | 14 | 19 | 1E | 23 | 28 | 2D | 32 | 37 | 3C | 41 | 46 | 4B |
6 | 0 | 6 | C | 12 | 18 | 1E | 24 | 2A | 30 | 36 | 3C | 42 | 48 | 4E | 54 | 5A |
7 | 0 | 7 | E | 15 | 1C | 23 | 2A | 31 | 38 | 3F | 46 | 4D | 54 | 5B | 62 | 69 |
8 | 0 | 8 | 10 | 18 | 20 | 28 | 30 | 38 | 40 | 48 | 50 | 58 | 60 | 68 | 70 | 78 |
9 | 0 | 9 | 12 | 1B | 24 | 2D | 36 | 3F | 48 | 51 | 5A | 63 | 6C | 75 | 7E | 87 |
A | 0 | A | 14 | 1E | 28 | 32 | 3C | 46 | 50 | 5A | 64 | 6E | 78 | 82 | 8C | 96 |
B | 0 | B | 16 | 21 | 2C | 37 | 42 | 4D | 58 | 63 | 6E | 79 | 84 | 8F | 9A | A5 |
C | 0 | C | 18 | 24 | 30 | 3C | 48 | 54 | 60 | 6C | 78 | 84 | 90 | 9C | A8 | B4 |
D | 0 | D | 1A | 27 | 34 | 41 | 4E | 5B | 68 | 75 | 82 | 8F | 9C | A9 | B6 | C3 |
E | 0 | E | 1C | 2A | 38 | 46 | 54 | 62 | 70 | 7E | 8C | 9A | A8 | B6 | C4 | D2 |
F | 0 | F | 1E | 2D | 3C | 4B | 5A | 69 | 78 | 87 | 96 | A5 | B4 | C3 | D2 | E1 |
\(\begin{matrix} & & A & E & {}_{16} \\ \times & & 3 & E & {}_{16} \\ \hline{} \end{matrix}\qquad\)
\(\begin{matrix} & & A & \underline E & {}_{16} \\ \times & & 3 & \underline E & {}_{16} \\ \hline{} & & C & 4 & {}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & & \underline A & E & {}_{16} \\ \times & & 3 & \underline E & {}_{16} \\ \hline{} & & C & 4 & {}_{16} \\ + & 8 & C & & {}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & & A & \underline E & {}_{16} \\ \times & & \underline 3 & E & {}_{16} \\ \hline{} & & C & 4 & {}_{16} \\ + & 8 & C & & {}_{16} \\ + & 2 & A & & {}_{16} \\ \end{matrix}\qquad\)
\(\begin{matrix} & & \underline A & E & {}_{16} \\ \times & & \underline 3 & E & {}_{16} \\ \hline{} & & & C & 4 & {}_{16} \\ + & & 8 & C & & {}_{16} \\ + & & 2 & A & & {}_{16} \\ + & 1 & E & & & {}_{16} \\ \end{matrix}\qquad\)
\(\begin{matrix} & & A & E & {}_{16} \\ \times & & 3 & E & {}_{16} \\ \hline{} & & & C & 4 & {}_{16} \\ + & & 8 & C & & {}_{16} \\ + & & 2 & A & & {}_{16} \\ + & 1 & E & & & {}_{16} \\ \hline{} & \overset{1}{1} & \overset{2}{8} & 2 & 4 & {}_{16} \\ \hline{} & 2 & A & 2 & 4 & {}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & A & 4 & D & {}_{16} \\ - & & 8 & C & {}_{16} \\ \hline{} &&&&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & A & 4 & D & {}_{16} \\ - & & 8 & C & {}_{16} \\ \hline{} &&&1&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & \dot A & 4 & D & {}_{16} \\ - & & 8 & C & {}_{16} \\ \hline{} &&C&1&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} & \dot A & 4 & D & {}_{16} \\ - & & 8 & C & {}_{16} \\ \hline{} &9&C&1&{}_{16} \end{matrix}\qquad\)
\(\begin{matrix} 8 & D & 6 & {}_{16} \\ & & & \end{matrix}\begin{array}{|llll} D_{16} & \\ \hline{} & \\ \end{array}\)
\(\begin{matrix} & 8 & D & 6 & {}_{16} \\ - & 8 & 2 & & \\ \hline{} & & B & 6 \end{matrix} \begin{matrix} \begin{array}{|llll} D & {}_{16} & \\ \hline{} A \end{array} \\ & \end{matrix}\)
\(\begin{matrix} & 8 & D & 6 & {}_{16} \\ - & 8 & 2 & & \\ \hline{} & & B & 6 \\ & - & B & 6 \\ \hline{} &&& 0 \end{matrix} \begin{matrix} \begin{array}{|llll} D & {}_{16} & \\ \hline{} A & E & {}_{16} \end{array} \\ & \\ & \\ & \end{matrix}\)
число \(X\) в P-ичной системе счисления: \[ X = a_n P^n + \ldots + a_1 P^1 + a_0 \]
Если разделить \(X\) на \(P\) с остатком, то получим
\[ \frac{X}{P} = \frac{a_n P^n + \ldots + a_1 P^1 + a_0}{P} \]
\[ \frac{X}{P} =a_n P^{n-1} + \ldots + a_1 + \frac{a_0}{P}, \]
Пример смешанного двоично-шестнадцатиричного числа: \[ {[1011_2][1110_2][1110_2][1111_2]}_{16} \]
Пример смешанного десятично-шестнадцатиричного числа:
\[ {[11][14][14][15]}_{16} \]
\[ \sum_{i=0}^n a_i P^i = \sum_{j=0}^{m} b_j P^{kj}\]
\[ a_n P^n + \ldots + a_{2k-1} P^{2k-1} + \ldots \\ + a_{k} P^{k} + a_{k-1} P^{k-1} + \ldots + a_0 \\ = b_m P^{km} + \ldots + b_1 P^k + b_0\]
\[ a_n P^n + \ldots + \left( a_{2k-1} P^{k-1} + \ldots \\ + a_{k}\right) P^{k} + a_{k-1} P^{k-1} + \ldots + a_0 \\= b_m P^{km} + \ldots + b_1 P^k + b_0.\]
\[ a_n P^n + \ldots + \left( a_{2k-1} P^{k-1} + \ldots \\ + a_{k}\right) P^{k} + a_{k-1} P^{k-1} + \ldots + a_0 \\= b_m P^{km} + \ldots + b_1 P^k + b_0.\]
Пользуясь методом неопределённых коэффициентов,
\[b_0 = a_{k-1} P^{k-1} + \ldots + a_0,\]
\[b_1 = a_{2k-1} P^{k-1} + \ldots + a_k,\]
\[\ldots\]
Пример:
\(1234_{10} = 10011010010_2\)
1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 |
Некоторые распространенные примеры:
Число разрядов | Тип в C++[^1] | Максимально представимое |
---|---|---|
8 | unsigned char |
255 |
16 | unsigned short |
65535 |
32 | unsigned int |
4 294 967 295 |
64 | unsigned long long |
18 446 744 073 709 551 615 |
#include <iostream>
#include <climits>
using namespace std;
int main() {
cout << "unsigned char " << sizeof(unsigned char) * CHAR_BIT
<< "\n" << "unsigned short " << sizeof(unsigned short) * CHAR_BIT
<< "\n" << "unsigned int " << sizeof(unsigned int) * CHAR_BIT
<< "\n" << "unsigned long " << sizeof(unsigned long) * CHAR_BIT
<< "\n" << "unsigned long long "
<< sizeof(unsigned long long) * CHAR_BIT
<< endl;
}
Типовый вывод:
unsigned char 8
unsigned short 16
unsigned int 32
unsigned long 64
unsigned long long 64