# I think Python made a mistake for this binary's result

#1

Guys, I think there is a mistake when we print the representation binary for 5/14.
rint int("1",2)
print int("10",2)
print int("111",2)
print int("0b100",2)
print int(bin(5),2)

# Print out the decimal equivalent of the binary 11001001.

print int("11001001", 2)

for PYTHON: #201 (I think it should be 21) because of the following reasons:
8'sbit 4'sbit 2'sbit 1'sbit ----------------------- 8'sbit 4'sbit 2'sbit 1'sbit
1 1 0 0 -------- +----------- 1 0 0 1
8 + 4 + 0 + 0=12 -------------------- 8 + 0 + 0 + 1=9

#2

201 is the correct value.

`````` 1    1   0   0   1   0   0  1
2^7  2^6         2^3        2^0
128 + 64    +     8     +    1   ==   201``````

#3

Consider the 4-bit number, `1111` which is decimal 15 (8+4+2+1), or hexadecimal `F`. The next bit to the left will be 2^4, or 16. So,

``10000 * 1111 is 11110000 or 240 (16 * 15).``

``11111111 or FF, 255.``

#4

Oh, ok. Thank you so much for your explanation of 201!

#5

10000 * 1111 is 11110000 or 240 (16 * 15)
For this example, you take the next bit to the left. What would it be if I take the next bit to the right:
0001 * 1111 is 1111001?
And why do you consider 5-bit(10000) number instead of 4-bit(1000) to represent 16?

#6

Consider the number 1 in terms of decimal base 10. When we shift the number to the left and insert a 0 as a placeholder for the 1's position, we get 10. Another shift to the left, with another 0 inserted as placeholder for ten's position, we get 100. Shift left again, we get 1000.

``````   1
10
100
1000``````

Notice that each shift left is 10 times the previous position in value.

` 1 X 10 => 10 10 X 10 => 100 100 X 10 => 10001000 X 10 => 10000`
This pattern repeats itself in all number bases. We can conveniently refer to the example above in examining binary (base 2) numbers, since there are only 1's and 0's.

Shift 1 to the left, we get 2. Shift 2 to the left we get 4, and again we get 8, and finally on the fourth shift left we get 16.

So a shift to the left is a doubling of the number, and a shift to the right is a halving of the number. The smallest number in base 2 is 0, the smallest non-zero number is 1. There are no decimal places in binary.

Now consider the number 9. Can we in one digit represent a larger integer? No. So when we add 1 to nine, the magnitude of the number goes up by 1. In arithmetic we call this a carry. In binary it is called a carry bit.

There is no way to represent a binary number larger than 15 in only 4-bits. It becomes necessary to introduce a carry bit, hence a 5-bit number.

We normally don't represent binary numbers with leading 0's any more than we would with decimal numbers. The left most bit is known as the highest order bit and its right most is the lowest order bit. Orders refer to magnitudes, which are exponential.

``````Lowest order bit magnitude  =>  0
Highest order bit magnitude  =>  4  (in our example of 16)``````

What gets raised to the order of magnitude? The base, 2. 2^0 is 1. 2^1 is 2, and so on.

#7

Damn Bro, you are awesome!