Bit - Binary to Decimal

> (Data|State) Management and Processing > (Data Type|Data Structure) > Number, Numeric, Quantity > Bit - Binary Number

1 - About

Decimal to binary number.

2 - Binary number with Radix to Decimal

Binary number with Radix to Decimal

1101.101

The binary number 1101.101 has the following digits:

Power of 2 3 2 1 0 −1 −2 −3
Binary digit 1 1 0 1 . 1 0 1

In Decimal, you get:

<math> \begin{array}{llr} 1101.101_2 &= 1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 + 1 \times 2^{-1} + 0 \times 2^{-2} + 1 \times 2^{-3} \\ &= 1 \times 8 + 1 \times 4 + 0 \times 2 + 1 \times 1 + 1 \times 0.5 + 0 \times 0.25 + 1 \times 0.125 \\ &= 8 + 4 + 0 + 1 + 0.5 + 0 + 0.125 \\ &= 13.625_{10} \end{array} </math>

Advertising

3 - Python

Python representation code to generate the mapping between decimal number and binary number (It work also in an other base)

>>> base = 2
>>> digits = set(range(base))
>>> {((base**2)*a + base*b + c):[a,b,c] for a in digits for b in digits for c in digits}

Output:

0: [0, 0, 0]
1: [0, 0, 1]
2: [0, 1, 0]
3: [0, 1, 1]
4: [1, 0, 0]
5: [1, 0, 1]
6: [1, 1, 0]
7: [1, 1, 1]

4 - Documentation / Reference

data/type/number/bit/bit2decimal.txt · Last modified: 2017/09/13 16:03 by gerardnico