-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBin Oct Hex examples.py
More file actions
42 lines (27 loc) · 1.38 KB
/
Bin Oct Hex examples.py
File metadata and controls
42 lines (27 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Generate computer numbers in binary base 2, hexadecimal base 16 and octal base
# 8. Type in ASCII codes and see what they look like. For example: 'print(bin(65))' is
# the ASCII code value for the capital letter 'A' in bibary base 2 as: '0b1000001'. Note:
# the '0b' is Python's prefix, which simply tells Python to work with binary base 2
# numbers.
'''----------------------------------------------------------------'''
# Convert any number into a binary base 2 number.
print(bin(255))
# Convert any number into a hexadecimal base 16 number.
print(hex(255))
# Convert any number into an octal base 8 number.
print(oct(255))
'''----------------------------------------------------------------'''
# Type and execute/run each of these program examples below and see what
# happens.
comp_nums=int(input('Please type any number to see its binary base 2 number \
value: ').strip())
print(f'The number {comp_nums} = the binary base 2 number value: \
{bin(comp_nums)}.')
comp_nums=int(input('Please type any number to see its hexadecimal base 16 \
number value: ').strip())
print(f'The number {comp_nums} = the hexadecimal base 16 number value: \
{hex(comp_nums)}.')
comp_nums=int(input('Please type any number to see its octal base 8 \
number value: ').strip())
print(f'The number {comp_nums} = the octal base 8 number value: \
{oct(comp_nums)}.')