decimal= 3.990
binaryr=""#reverse binary number lsb to msb
x=decimal #copy
while x0:
binaryr += str(x%2)
x//=2
binary="("+binaryr[::-1]+")₂"#msb to lsb
decimal=f"({decimal})₁₀"
print(f"decimal {decimal} = binary {binary}")
Predict the output

Posted on by