NUMBER SYSTEM Notes 2024-25
NUMBER SYSTEM Notes 2024-25
They first convert that data and instructions into binary form,
which is easily understood by computers.
Take out the number system from our society, and we will
return to the “Stone Age”.
Each of these number systems has its advantages and disadvantages, and
each is used in different applications. For example, the binary number system
is used to represent and manipulate data in computer hardware, while the
decimal number system is used for everyday calculations. The octal and
hexadecimal systems are commonly used in computer programming and
digital electronics because they are more compact and easier to read than
binary.
Understand the values of each digit in the current number system: Before you
can convert a number, you need to understand how the current number
system works. For example, in the binary system, each digit represents a
power of two, starting with 20 on the right side.
Check your answer: To verify your answer, you can convert the number back
to the original base and make sure it matches the original number.
Example: Convert the decimal number 158 to binary, octal, and hexadecimal.
Below is the conversion one by one:
Binary Conversion:
To convert a decimal number to binary, we divide the decimal number by 2
repeatedly and write the remainder in reverse order.
158 / 2 = 79 remainder 0
79 / 2 = 39 remainder 1
39 / 2 = 19 remainder 1
19 / 2 = 9 remainder 1
9 / 2 = 4 remainder 1
4 / 2 = 2 remainder 0
2 / 2 = 1 remainder 0
1 / 2 = 0 remainder 1
Octal Conversion:
To convert a decimal number to an octal, we divide the decimal number by 8
repeatedly and write the remainder in reverse order.
158 / 8 = 19 remainder 6
19 / 8 = 2 remainder 3
2 / 8 = 0 remainder 2
Hexadecimal Conversion:
To convert a decimal number to hexadecimal, we divide the decimal number
by 16 repeatedly and write the remainder in reverse order. For remainders
greater than 9, we use letters A-F.
Output
Decimal: 158
Binary: 10011110
Octal: 236
Hexadecimal: 9E
Code Implementation
C++
#include <iostream>
#include <stack>
using namespace std;
void decimalToBinary(int decimalNum) {
stack<int> binaryNum;
while(decimalNum > 0) {
binaryNum.push(decimalNum % 2);
decimalNum /= 2;
}
cout << "Binary equivalent: ";
while(!binaryNum.empty()) {
cout << binaryNum.top();
binaryNum.pop();
}
cout << endl;
}
void decimalToOctal(int decimalNum) {
stack<int> octalNum;
while(decimalNum > 0) {
octalNum.push(decimalNum % 8);
decimalNum /= 8;
}
cout << "Octal equivalent: ";
while(!octalNum.empty()) {
cout << octalNum.top();
octalNum.pop();
}
cout << endl;
}
void decimalToHexadecimal(int decimalNum) {
stack<char> hexNum;
while(decimalNum > 0) {
int remainder = decimalNum % 16;
if(remainder < 10) {
hexNum.push(remainder + '0');
}
else {
hexNum.push(remainder - 10 + 'A');
}
decimalNum /= 16;
}
cout << "Hexadecimal equivalent: ";
while(!hexNum.empty()) {
cout << hexNum.top();
hexNum.pop();
}
cout << endl;
}
int main() {
int decimalNum;
cout << "Enter a decimal number: ";
cin >> decimalNum;
decimalToBinary(decimalNum);
decimalToOctal(decimalNum);
decimalToHexadecimal(decimalNum);
return 0;
}
nput
158
Output
Enter a decimal number: Binary equivalent: 10011110
Hexadecimal equivalent: 9E
Explanation:
The conversion of a number system in computer involves dividing the given
number by the base of the target number system and writing the remainder in
reverse order. For binary, the base is 2, for octal, it is 8, and for hexadecimal,
it is 16. In each step, we divide the quotient obtained in the previous step by
the base of the target number system and take the remainder. We continue
this process until the quotient becomes zero. Finally, we write the remainder
obtained in reverse order to get the equivalent number in the target number
system. The program first prompts the user to enter a decimal number. It then
calls three different functions for converting the decimal number to binary,
octal, and hexadecimal. The functions use a stack data structure to store the
remainder obtained during the division method of conversion. Finally, the
program outputs the equivalent values in binary, octal, and hexadecimal.
Conclusion
Number system theory studies mathematical systems that describe how
numbers are represented and manipulated. There are several types of
number systems, including the decimal system, binary system, octal system,
and hexadecimal system, among others. The theory of number systems
includes concepts such as place value, conversion between different number
systems, addition, subtraction, multiplication, and division. It also includes
advanced topics such as modular arithmetic, number theory, and
cryptography. In computer science, number system theory is crucial in digital
electronics, programming languages, and computer networking.
Understanding the theory of number systems is essential for anyone who
wants to work in these fields. It also has applications in various other fields,
including finance, physics, and engineering.