# Part B : Chapter 2 : Digital System¶

## Example 2.12 Page no :2.24¶

In [1]:
# Variables
binary = '11010';				#given binary value

# Calculations
decimal = int(binary,2);				#equivalent decimal

# Results
print "Equivalent decimal value is %d"%decimal

Equivalent decimal value is 26


## Example 2.13 Page no :2.25¶

In [2]:
# Variables
decimal = 26;				#given decimal value

# Calculations
binary = bin(decimal);				#equivalent binary value

# Results
print "Equivalent binary value is ",binary

Equivalent binary value is  0b11010


## Example 2.15 Page no : 2.26¶

In [3]:
# Variables
hex1 = '0xA013';				#given hexadecimal value

# Calculations
dec = int(hex1,16);				#equivalent decimal value

# Results
print "Equivalent decimal value is",dec

Equivalent decimal value is 40979


## Example 2.16 Page no :2.26¶

In [4]:
# Variables
dec = 7046;				#given decimal value

# Calculations
hex = hex(dec);				#equivalent hexadecimal value

# Results

Equivalent hexadecimal value is 0x1b86


## Example 2.17 Page no :2.27¶

In [6]:
# Variables
hex1 = '0xF851';				#given hexadecimal value

# Calculations
dec = int(hex1,16);				#equivalent decimal value
bin1 = bin(dec);				#equivalent binary value

# Results
print "Equivalent binary value is",bin1

Equivalent binary value is 0b1111100001010001


## Example 2.18 Page no :2.27¶

In [7]:
# Variables
bin1 = '111011011000100';				#given binary value

# Calculations
dec = int(bin1,2);				#equivalent decimal value
hex1 = "0x%X"%dec;				#equivalent hexadecimal value

# Results

Equivalent hexadecimal value is 0x76C4