Computer Science, asked by rawtaram6618, 11 months ago

Python program that takes a number as input and find first high bit(1) in its binary re form

Answers

Answered by sswaraj04
0

Answer:

x=int(input("enter the number"))

y=0

while True:

   if(x<10):

       y=x

       break

   x=x//10

print("highest bit is",y)

print("It's binary is")

while True:

   if(y==1):

       print("1")

       break

   print(y%2,end='')

   y=y//2

Explanation:

first we have to take input

now we will find highest bit

for it we will simply divide the number by 10 till we reach the most significant digit eg- 256/10 =25 ;25/10=2 ; 2 is highest bit

10//2 results integer while 10/2 results float

now we will find binary by simply finding remainder on dividing by 2 and prinitng on each step till value become 1

i suppose you know how to find binary from decimal

Hope it helps:-)

Similar questions