Monday, 27 May 2019

Decimal to Binary conversion

Decimal number (Ex: 10) to Binary Conversion:
















1 byte is 8 bits so remaining are filled with 0’s
a=10 à0000 1010

b=11













b=11->0000 1011

So
a=10->0000 1010


b=11->0000 1011

Steps:
Divide this number by 2 and ignore the remainder, keep repeating this process till we get 1

(1.) 10 divide by 2 which gives 5
     5 <--10  <---

(2.) Divide by 2 we get 2, ignore remainder 1
   i.e 2<-- 5 <--10

(3.) 2 divide by 2 we get 1, ignore remainder 0
   i.e 1<-- 2<-- 5<-- 10

(4.) Now we are going to write 1 below any of the odd number
   and 0 below any of the even number.
   i.e write 1 for odd numbers; 0 for even number
          1  2  5  10
   i.e   1  0  1    0
so 10=1010 (In binary)
Unicode & Character Encodings in Python: A Painless Guide

No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...