NTA UGC NET 2023 » NTA Study Materials » Computer Science » Representation of Fractions on a Computer

Representation of Fractions on a Computer

Similar to representing fractions on the number line, the computer also uses different methods for representing the numbers, such as signed representation, etc.

When we study mathematics in school, teachers teach us about representing fractions on the number line. However, suppose we want to represent fractions in a computer program. In that case, we cannot draw a number line because the computer only understands the language of binary numbers that are 0 and 1. A computer and other digital systems use a binary number system to represent different types of information in the computer. Moreover, the various alphanumeric characters we type are stored as binary numbers.

Therefore, if you are interested in studying computer science concepts, it is necessary that you study binary number systems because representing fractions on the number line doesn’t help in storing them in a computer. This article will give you knowledge about how the fractions are stored in a computer. But before knowing the way in which the fraction is stored on a computer, it is necessary that you know fixed and floating number representations.

Storing a real number on the computer involves the implementation of two major approaches. These alternatives are fixed point representation and floating point representation. When we write a fraction, there are two numbers: one is the numerator, and the other is the denominator. A computer converts the fraction into a decimal format and then stores it in the system using binary numbers. Thus, it is important to understand how the computers store this data using the fixed point and floating point representations.

Fixed Point Representation

While representing fractions on the number line, we follow a step-by-step procedure. Similarly, when a computer stores data, it follows a particular procedure. The number of digits available after the decimal point cannot be changed in fixed point representation. Thus, if the initial number contains two digits after the decimal point, then every number stored in that directory will have two numbers. However, if a number has three digits after the decimal point, it is converted to the nearest number and then stored in the directory. A fixed point representation has a sign field, integer field, and fractional field.

Like representing fractions on the number line, the computer also uses different methods to represent the numbers. The ways to represent the numbers on a computer are as follows:

  • Signed representation of numbers –(2(k-1) – 1) to (2(k-1) – 1), where k is the number of bits

  • Representation of numbers using 1’s complement: the range is –(2(k-1) – 1) to (2(k-1) – 1), k is the number of bits

  • Representation of numbers using 2’s complement: the range is –(2(k-1)) to (2(k-1) – 1).

Floating Point Representation

In floating point representation, the quantity of bits for an integer or the fractional part isn’t constant. However, this representation system specifies some bits for the number mantissa and some bits for the decimal places called the exponent.

The floating point representation consists of two parts. The first part of the representation is called the mantissa, which shows the signed number. The second part of the representation shows the position of the decimal point and is known as the exponent. The mantissa in the floating point representation can either be a fraction or an integer. The floating point representation is generally written in the format M × re.

In the floating point representation, the mantissa m and the exponent e are represented physically. The representation of a number using floating point representation is the same, except that the system uses a base 2 to represent the exponent.

Representation of Fractions

In fractions, one number is written above a horizontal line, and one number is written below it. The fractions are real numbers. Hence, it is necessary to understand the representation techniques used for representing them.

Representation of fractions in a computer is necessary in many cases. For representing a signed fraction, it is essential to figure out the digit present next to the most significant bit (MSB) in the sequence. The fixed point numbers are those in which the binary point is at a constant position. But in the case of unsigned fractions, the binary point is located at the extreme left end.

To identify the type of fraction, you must find out the location of the imaginary point. Suppose the imaginary point is located at the rightmost end, then the number is called an integer. But the presence of an imaginary point on the leftmost end ensures that the number is an unsigned fraction. Now, if the location of the imaginary bit is to the right of the most significant bit, then the number is a signed fraction, and the location of a point in the middle of the sequence ensures that the number is an integer or fraction.

There is a rule for the representation of fractions. According to the rule, the least quantity of non-zero fractions that can be represented is 2(n-1), and the least word size of the representation has to be 8 bits.

Conclusion

We all have studied representing fractions on the number line. But as a computer science student or enthusiast, it is necessary for you to understand the way in which the fractions are represented in a computer program. This article enlightens the readers about the various ways in which real numbers are represented in a computer program. When a reader skims through this article, they will learn the following outcomes.

  • The real numbers are represented using two techniques: fixed point representation and floating point representation

  • In fixed point representation, the quantity of numbers present after the decimal point stays fixed. While in the case of floating point numbers, there is no specific limit to the number of numbers after the decimal point

  • In the case of fixed point representation, if there are more than the specified number, the decimal number is converted to the nearest number

  • In fractional numbers, the location of the imaginary point decides whether a number is an integer, unsigned number, signed or unsigned fraction

faq

Frequently asked questions

Get answers to the most common queries related to the NTA Examination Preparation.

Can we represent all fractions in binary?

Ans. A binary number system can only represent those numbers as a finite fraction in which the denominator contains ...Read full

What is floating point number representation?

Ans. The depiction of binary numbers in exponential form is known as floating point representation. In floating poin...Read full

What is a character in computer science?

Ans. In computer science, a character is defined as a display unit for information. This display unit is equal to on...Read full

How are natural numbers represented in computers?

Ans. To show the natural numbers in a computer, the number of bits used for coding it is defined. Once the number of...Read full