In [1]:
bin_num = 0b10
oct_num = 0o10
hex_num = 0x10
print(bin_num)
print(oct_num)
print(hex_num)
In [2]:
Bin_num = 0B10
Oct_num = 0O10
Hex_num = 0X10
print(Bin_num)
print(Oct_num)
print(Hex_num)
In [3]:
print(type(bin_num))
print(type(oct_num))
print(type(hex_num))
In [4]:
print(type(Bin_num))
print(type(Oct_num))
print(type(Hex_num))
In [5]:
result = 0b10 * 0o10 + 0x10
print(result)
In [6]:
print(0b111111111111 is 0b1_1_1_1_1_1_1_1_1_1_1_1)
In [7]:
bin_num = 0b1111_1111_1111
print(bin_num)
In [8]:
i = 255
bin_str = bin(i)
oct_str = oct(i)
hex_str = hex(i)
print(bin_str)
print(oct_str)
print(hex_str)
In [9]:
print(type(bin_str))
print(type(oct_str))
print(type(hex_str))
In [10]:
bin_str = format(i, 'b')
oct_str = format(i, 'o')
hex_str = format(i, 'x')
print(bin_str)
print(oct_str)
print(hex_str)
In [11]:
print(type(bin_str))
print(type(oct_str))
print(type(hex_str))
In [12]:
bin_str = format(i, '#b')
oct_str = format(i, '#o')
hex_str = format(i, '#x')
print(bin_str)
print(oct_str)
print(hex_str)
In [13]:
bin_str = format(i, '08b')
oct_str = format(i, '08o')
hex_str = format(i, '08x')
print(bin_str)
print(oct_str)
print(hex_str)
In [14]:
bin_str = format(i, '#010b')
oct_str = format(i, '#010o')
hex_str = format(i, '#010x')
print(bin_str)
print(oct_str)
print(hex_str)
In [15]:
print('bin is {:08b}'.format(i))
print('oct is {:08o}'.format(i))
print('hex is {:08x}'.format(i))
In [16]:
dec_num = int('10')
bin_num = int('10', 2)
oct_num = int('10', 8)
hex_num = int('10', 16)
print(dec_num)
print(bin_num)
print(oct_num)
print(hex_num)
In [17]:
print(type(dec_num))
print(type(bin_num))
print(type(oct_num))
print(type(hex_num))
In [18]:
dec_num = int('10', 0)
bin_num = int('0b10', 0)
oct_num = int('0o10', 0)
hex_num = int('0x10', 0)
print(dec_num)
print(bin_num)
print(oct_num)
print(hex_num)
In [19]:
Bin_num = int('0B10', 0)
Oct_num = int('0O10', 0)
Hex_num = int('0X10', 0)
print(Bin_num)
print(Oct_num)
print(Hex_num)
In [20]:
a = '0b1001'
b = '0b0011'
c = int(a, 0) + int(b, 0)
print(c)
print(bin(c))
In [21]:
a_0b = '0b1110001010011'
a_0x = format(int(a, 0), '#010x')
a_0o = format(int(a, 0), '#010o')
print(a_0x)
print(a_0o)