# Системы счисления

## Теория

В системе счисления с основанием $$b$$ всего $$b$$ цифр, с числовыми значениями $${0,1,2,\dots, b-1}$$.

Число $$N$$ записывается цифрами $$d\_{n-1}d\_{n-2}\dots d\_2d\_1d\_0$$ в системе счисления с основанием $$b$$ означает, что $$N=d\_{n-1}\cdot b^{n-1} + d\_{n-2}\cdot b^{n-2}+\dots + d\_2\cdot b^2 + d\_1\cdot b^1 + d\_0\cdot b^0$$.

***

## Список цифр (любая СС)

### Перевод в СС

```python
def base(n, b):
    digits = []
    while n > 0:
        digits.append(n % b)
        n //= b
    return digits[::-1]
```

### Перевод из СС

```python
def number(digits, b):
    n = 0
    for digit in digits:
        n = n * b + digit
    return n
```

### Проверка функций

```python
for n in range(1, 1000):
    for b in range(2, 20):
        if n != number(base(n, b), b):
            print("ERROR")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://andrewmaths.gitbook.io/conspects/inf/sistemy-schisleniya.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
