Python
Computer number systems are essential for understanding how data is represented and
manipulated within a computer. The most common number systems used in computing are:
1. Decimal (Base 10)
2. Binary (Base 2)
3. Octal (Base 8)
4. Hexadecimal (Base 16)
1. Decimal to Binary
To convert a decimal number to binary, divide the number by 2 and record the remainder.
Repeat the process with the quotient until you get a quotient of 0. The binary number is the
sequence of remainders read from bottom to top.
Example: Convert 25 to binary
2. Binary to Decimal
To convert a binary number to decimal, multiply each bit by 2 raised to the power of its
position from right to left, starting at 0, and sum the results.
Example: Convert 11001 to decimal
3. Decimal to Octal
To convert a decimal number to octal, divide the number by 8 and record the remainder.
Repeat the process with the quotient until you get a quotient of 0. The octal number is the
sequence of remainders read from bottom to top.
Example: Convert 25 to octal
Python
4. Octal to Decimal
To convert an octal number to decimal, multiply each digit by 8 raised to the power of its
position from right to left, starting at 0, and sum the results.
Example: Convert 31 to decimal
5. Decimal to Hexadecimal
To convert a decimal number to hexadecimal, divide the number by 16 and record the
remainder. Repeat the process with the quotient until you get a quotient of 0. The
hexadecimal number is the sequence of remainders read from bottom to top.
Example: Convert 25 to hexadecimal
6. Hexadecimal to Decimal
To convert a hexadecimal number to decimal, multiply each digit by 16 raised to the power
of its position from right to left, starting at 0, and sum the results.
Example: Convert 19 to decimal
7. Binary to Octal
To convert binary to octal, group the binary digits into sets of three starting from the right.
Convert each group to its octal equivalent.
Example: Convert 11001 to octal
Python
8. Octal to Binary
To convert octal to binary, convert each octal digit to its 3-bit binary equivalent.
Example: Convert 31 to binary
9. Binary to Hexadecimal
To convert binary to hexadecimal, group the binary digits into sets of four starting from the
right. Convert each group to its hexadecimal equivalent.
Example: Convert 11001 to hexadecimal
10. Hexadecimal to Binary
To convert hexadecimal to binary, convert each hexadecimal digit to its 4-bit binary
equivalent.
Example: Convert 19 to binary
Python
In Python, there are several built-in data types that you can use to store and manipulate data.
Here is a comprehensive list of the main data types along with examples of how to use them
in Python:
1. Numeric Types
o Integer: int
o Floating point: float
o Complex number: complex
2. Sequence Types
o String: str
o List: list
o Tuple: tuple
o Range: range
3. Set Types
o Set: set
o Frozen set: frozenset
4. Mapping Type
o Dictionary: dict
5. Boolean Type
o Boolean: bool
6. Binary Types
o Bytes: bytes
o Byte array: bytearray
o Memory view: memoryview
Here is a Python script demonstrating the declaration and usage of these data types:
Q. Write a Python program that creates a dictionary to store information about a
employee. The dictionary should include keys for name, age, employee id, and work
load (a list ). Print the dictionary.
Python
Ans:
Python Examples:
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python
Python