M
M
Maxim Pavlov2017-09-01 12:57:25
Python
Maxim Pavlov, 2017-09-01 12:57:25

How to change the number size?

If you try to store a number in an N-bit variable that requires more than N bits for its record, then the high-order bits of the number will be cut off. For example, if you store the value 10 in a two-bit unsigned variable, then the value of this variable will be equal to 2.
I did this:
A = int('10', 2)
print A#Output : 2
Is this correct, or is it just a coincidence?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey, 2017-09-01
@liberaven

two bits will either be 00 or 01 or 10 or 11. This way you will only get 0, 1, 2, 3 in decimal.

A
Astrohas, 2017-09-01
@Astrohas

This is the conversion of the binary number 10 to decimal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question