Python Practice › Tuple Programs › Program 65

Binary tuple to an integer

EasyTuple Programs · 65 of 70

Write a Python program to convert a tuple of binary digits into an integer.

Advertisement
Input
(1, 0, 0)
Output
4

Approach

  1. Join the digits and use int(text, 2).

Solution

Python
bits = (1, 0, 0)print(int("".join(map(str, bits)), 2))
Output
4
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs