Microcontroller Embedded C Programming Lecture 62| Manipulating decimal numbers in ‘C’

 

Manipulating decimal numbers in ‘C’

 

 

In this article, let’s understand Manipulating decimal numbers in ‘C.’ Let’s explore. 

 

Representation of decimal numbers in ā€˜Cā€™

  • A Decimal Number contains a Decimal Point.
    • For example, 125.55 is a decimal number(a real number). 
  • In computer memory, the real numbers are stored according to the representation standardization by the IEEE standard 754.
  • IEEE754 floating-point representation is an approximate representation of real numbers.
  • All computer systems and microcontrollers nowadays use this standard to store real numbers in memory. 
  • If you are working with numbers that have a fractional part or in case you are using integers that don’t fit into a long data type, then we can use floating-point representation.

So, we have discussed about integer data types. Those data are not stored according to this standard remember.

 

Manipulating decimal numbers in 'C'
Figure 1. Real numbers

 

Let’s consider a number that is too small in nature. For example, the charge of an electron.

How do you represent this in your  ‘C’ program? 

You cannot use integer data types. So, you have to use floating-point data types, which are called float and double in ‘C.’ So, we will explore that in a moment.

Let’s consider a very big real number. Let’s say the distance between Earth and Andromeda galaxy. It’s a very big number. So, you cannot fit this data by using an integer data type like long long because it’s a very big number. That’s why remember that in ‘C,’ too small or too big numbers or numbers having a fractional part are represented using floating-point representation data types such as float and double.

 

In summary, why do we need floating-point representation? 

  • To store, a too-small number in memory, 
  • To store, a too big number in memory, 
  • To store a number which has a fractional part, or we can also call it a decimal number.

In the following article, let’s explore the IEEE-754 floating-point standard to store floating-point numbers.

 

FastBit Embedded Brain Academy Courses

Click here: https://fastbitlab.com/course1

 

FastBitLab

The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.