Mathematics For Computer Science
Mathematics is the language of logic, structure, and precision, and it plays a fundamental role in
shaping computer science. From the binary language of computers to advanced concepts like
machine learning and cryptography, math provides the foundation for nearly every area of
computing. Mathematics provides you with the tools to think logically, solve problems efficiently,
and build systems that are secure, scalable, and intelligent. It’s not just about numbers; it’s about
structured thinking, which is at the core of computer science.
Here’s what learning math enables you to do:
• Help in Solving Problems: Understand how to approach problems with logic and precision.
• Write Efficient Code: Analyze and improve program performance using mathematical
reasoning.
• Master Core Concepts: Grasp foundational topics like data structures, cryptography, AI,
and graphics.
• Build Secure Systems: Use number theory and modular arithmetic for encryption and data
protection.
• Succeed in Advanced Fields: Tackle machine learning, simulations, and theoretical
computer science with confidence.
Number Theory
Numbers are not only the mere symbols on a page but there is much more significance of
numbers. In the study of mathematics, numerous number systems exist, each with its own
significance and applications. From the familiar decimal system we use daily to the intriguing
worlds of binary, octal, and hexadecimal, these systems offer unique perspectives on numerical
representation. In this article, we explore the concepts of number systems and also learn about
these different number system types.
The number system includes different types of numbers for example prime numbers, odd numbers,
even numbers, rational numbers, whole numbers, etc. These numbers can be expressed in the
form of figures as well as words accordingly. For example, numbers like 40 and 65 expressed in
the form of figures can also be written as forty and sixty-five.
A Number system or numeral system is defined as an elementary system to express numbers and
figures. It is the unique way of representing of numbers in arithmetic and algebraic structure.
Types of Number Systems
Based on the base value and the number of allowed digits, number systems are of many types.
The four common types of Number systems are:
• Decimal Number System
• Binary Number System
• Octal Number System
• Hexadecimal Number System
Decimal Number System
A number system with a base value of 10 is termed a Decimal number system. It uses 10 digits
i.e. 0-9 for the creation of numbers. Here, each digit in the number is at a specific place with a
place value of a product of different powers of 10. Here, the place value is termed from right to
left as the first place value called units, second to the left as Tens, so on Hundreds, Thousands,
etc. Here, units have a place value of 100, tens have a place value of 101, hundreds as 102,
thousands as 103, and so on.
For example, 12265 has place values as,
(1 × 104) + (2 × 103) + (2 × 102) + (6 × 101) + (5 × 100)
= (1 × 10000) + (2 × 1000) + (2 × 100) + (6 × 10) + (5 × 1)
= 10000 + 2000 + 200 + 60 + 5
= 12265
Binary Number System
A number System with a base value of 2 is termed a Binary number system. It uses 2 digits i.e. 0
and 1 for the creation of numbers. The numbers formed using these two digits are termed Binary
Numbers. The binary number system is very useful in electronic devices and computer systems
because it can be easily performed using just two states ON and OFF i.e. 0 and 1.
Decimal Numbers 0-9 are represented in binary as 0, 1, 10, 11, 100, 101, 110, 111, 1000, and 1001
For example, 14 can be written as 1110, 19 can be written as 10011, and 50 can be written as
110010.
Octal Number System
Octal Number System is one in which the base value is 8. It uses 8 digits i.e. 0-7 for the creation of
Octal Numbers. Octal Numbers can be converted to Decimal values by multiplying each digit with
the place value and then adding the result. Here the place values are 80, 81, and 82. Octal
Numbers are useful for the representation of UTF8 Numbers. Example,
(81)10 can be written as (121)8
(125)10 can be written as (175)8
Hexadecimal Number System
A number System with a base value of 16 is known as Hexadecimal Number System. It uses 16
digits for the creation of its numbers. Digits from 0-9 are taken like the digits in the decimal
number system but the digits from 10-15 are represented as A-F i.e. 10 is represented as A, 11 as
B, 12 as C, 13 as D, 14 as E, and 15 as F. Hexadecimal Numbers are useful for handling memory
address locations. Examples,
(185)10 can be written as (B9)16
(5440)10 can be written as (1540)16
(4265)10 can be written as (10A9)16
Sample Problems on Types of Number System
Problem 1: Convert (4525)8 into a decimal.
Solution:
(4525)8 = 4 × 83 + 5 × 82 + 2 × 81 + 5 × 80
⇒ 45258 = 4 × 512 + 5 × 64 + 2 × 8 + 5 × 1
⇒ 45258 = 2048 + 320 + 16 + 5
⇒ 45258 = 238910
Base Conversions for Number System
Electronic and digital systems use various number systems such as Decimal, Binary, Hexadecimal
and Octal, which are essential in computing.
• Binary (base-2) is the foundation of digital systems.
• Hexadecimal (base-16) and Octal (base-8) are commonly used to simplify the
representation of binary data.
• The Decimal system (base-10) is the standard system for everyday calculations.
• Other number systems like Duodecimal (base-12), are less commonly used but have
specific applications in certain fields.
Types of Number System
There are four common types of number systems based on the radix or base of the number :
1. Decimal Number System
• The Decimal system is a base-10 number system.
• It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.
• Each digit’s place value is a power of 10 (e.g., 100, 101, 102).
• It is the standard system for everyday counting and calculations.
2. Binary Number System
• The Binary system is a base-2 number system.
• It uses two digits: 0 and 1.
• Each digit’s place value is a power of 2 (e.g., 20, 21, 22).
• The Binary system is the foundation for data representation in computers and digital
electronics.
3. Octal Number System
• The Octal system is a base-8 number system.
• It uses eight digits: 0, 1, 2, 3, 4, 5, 6 and 7.
• Each digit’s place value is a power of 8 (e.g., 80, 81, 82).
• It is often used to simplify the representation of binary numbers by grouping them into
sets of three bits.
4. Hexadecimal Number System
• The Hexadecimal system is a base-16 number system.
• It uses sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E and F (where A = 10, B = 11,
etc.).
• Each digit’s place value is a power of 16 (e.g., 160, 161, 162).
• Hexadecimal simplifies binary by representing every 4 bits as one digit (0-F).
1. Decimal to Binary Number System Conversion
For Integer Part:
• Divide the decimal number by 2.
• Record the remainder (0 or 1).
• Continue dividing the quotient by 2 until the quotient is 0.
• The binary equivalent is the remainders read from bottom to top.
For Fractional Part:
• Multiply the fractional part by 2.
• Record the integer part (0 or 1).
• Take the fractional part of the result and repeat the multiplication.
• Continue until the fractional part becomes 0 or reaches the desired precision.
• The binary equivalent is the integer parts recorded in sequence.
For Integer Part (10):
• Divide 10 by 2 → Quotient = 5, Remainder = 0
• Divide 5 by 2 → Quotient = 2, Remainder = 1
• Divide 2 by 2 → Quotient = 1, Remainder = 0
• Divide 1 by 2 → Quotient = 0, Remainder = 1
Reading the remainders from bottom to top gives 1010.
For Fractional Part (0.25):
• Multiply 0.25 by 2 → Result = 0.5, Integer part = 0
• Multiply 0.5 by 2 → Result = 1.0, Integer part = 1
The fractional part ends here as the result is now 0. Reading from top to bottom gives 01.
Thus, the binary equivalent of (10.25)10 is (1010.01)2.
2. Binary to Decimal Number System Conversion
For Integer Part:
• Write down the binary number.
• Multiply each digit by 2 raised to the power of its position, starting from 0 (rightmost digit).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the binary integer.
For Fractional Part:
• Write down the binary fraction.
• Multiply each digit by 2 raised to the negative power of its position, starting from -1 (first
digit after the decimal point).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the binary fraction.
Example: (1010.01)2
1x23 + 0x22 + 1x21+ 0x20 + 0x2 -1 + 1x2 -2 = 8+0+2+0+0+0.25 = 10.25
Thus, (1010.01)2 = (10.25)10
3. Decimal to Octal Number System Conversion
For Integer Part:
• Divide the decimal number by 8.
• Record the remainder (0 to 7).
• Continue dividing the quotient by 8 until the quotient is 0.
• The octal equivalent is the remainders read from bottom to top.
For Fractional Part:
• Multiply the fractional part by 8.
• Record the integer part (0 to 7).
• Take the fractional part of the result and repeat the multiplication.
• Continue until the fractional part becomes 0 or reaches the desired precision.
• The octal equivalent is the integer parts recorded in sequence.
Example: (10.25)10
For Integer Part (10):
• Divide 10 by 8 → Quotient = 1, Remainder = 2
• Divide 1 by 8 → Quotient = 0, Remainder = 1
Octal equivalent = 12 (write the remainder, read from bottom to top). So, the octal equivalent of
the integer part 10 is 12.
For Fractional Part (0.25):
• Multiply 0.25 by 8 → Result = 2.0, Integer part = 2
The fractional part ends here as the result is now 0. So, the octal equivalent of the fractional
part 0.25 is 0.2.
The octal equivalent of (10.25)10 = (12.2)8
4. Octal to Decimal Number System Conversion
For Integer Part:
• Write down the octal number.
• Multiply each digit by 8 raised to the power of its position, starting from 0 (rightmost digit).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the octal integer.
For Fractional Part:
• Write down the octal fraction.
• Multiply each digit by 8 raised to the negative power of its position, starting from -1 (first
digit after the decimal point).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the octal fraction.
Example: (12.2)8
1 x 81 + 2 x 80 +2 x 8-1 = 8+2+0.25 = 10.25
Thus, (12.2)8 = (10.25)10
5. Decimal to Hexadecimal Conversion
For Integer Part:
• Divide the decimal number by 16.
• Record the remainder (0-9 or A-F).
• Continue dividing the quotient by 16 until the quotient is 0.
• The hexadecimal equivalent is the remainders read from bottom to top.
For Fractional Part:
• Multiply the fractional part by 16.
• Record the integer part (0-9 or A-F).
• Take the fractional part of the result and repeat the multiplication.
• Continue until the fractional part becomes 0 or reaches the desired precision.
• The hexadecimal equivalent is the integer parts recorded in sequence.
Example: (10.25)10
Integer part:
• 10 ÷ 16 = 0, Remainder = A (10 in decimal is A in hexadecimal)
Hexadecimal equivalent = A
Fractional part:
• 0.25 × 16 = 4, Integer part = 4
Hexadecimal equivalent = 0.4
Thus, (10.25)10 = (A.4)16
6. Hexadecimal to Decimal Conversion
For Integer Part:
• Write down the hexadecimal number.
• Multiply each digit by 16 raised to the power of its position, starting from 0 (rightmost
digit).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the hexadecimal integer.
For Fractional Part:
• Write down the hexadecimal fraction.
• Multiply each digit by 16 raised to the negative power of its position, starting from -1 (first
digit after the decimal point).
• Add up the results of these multiplications.
• The sum is the decimal equivalent of the hexadecimal fraction.
Example: (A.4)16
(A × 160) + (4 × 16-1) = (10 × 1) + (4 × 0.0625)
Thus, (A.4)16 = (10.25)10
7. Hexadecimal to Binary Number System Conversion
To convert from Hexadecimal to Binary:
• Each hexadecimal digit (0-9 and A-F) is represented by a 4-bit binary number.
• For each digit in the hexadecimal number, find its corresponding 4-bit binary equivalent
and write them down sequentially.
Example: (3A)16
• (3)16 = (0011)2
• (A)16 = (1010)2
Thus, (3A)16 = (00111010)2
8. Binary to Hexadecimal Number System Conversion
To convert from Binary to Hexadecimal:
• Start from the rightmost bit and divide the binary number into groups of 4 bits each.
• If the number of bits isn't a multiple of 4, pad the leftmost group with leading zeros.
• Each 4-bit binary group corresponds to a single hexadecimal digit.
• Replace each 4-bit binary group with the corresponding hexadecimal digit.
Example: (1111011011)2
0011 1101 1011
| | |
3DB
Thus, (001111011011 )2 = (3DB)16
9. Binary to Octal Number System
To convert from binary to octal:
• Starting from the rightmost bit, divide the binary number into groups of 3 bits.
• If the number of bits is not a multiple of 3, add leading zeros to the leftmost group.
• Each 3-bit binary group corresponds to a single octal digit.
• Replace each 3-bit binary group with the corresponding octal digit.
Example: (111101101)2
111 101 101
| | |
755
Thus, (111101101)2 = (755)8
10. Octal to Binary Number System Conversion
To convert from octal to binary:
• Each octal digit (0-7) corresponds to a 3-bit binary number.
• For each octal digit, replace it with its corresponding 3-bit binary equivalent.
Example: (153)8
• Break the octal number into digits: 1, 5, 3
• Convert each digit to binary:
o 1 in octal = 001 in binary
o 5 in octal = 101 in binary
o 3 in octal = 011 in binary
Thus, (153)8 = (001101011)2