Hi,
I am not able to understand the difference of
1) what is the difference of unsigned and signed.
As both can have same amount of memory eg. unsigned int and signed int have 16 bits(depending upon compiler). then what will be the benefit of signed.
2) what is the difference between float and double variables?
I have heard that float is a single precision and double is two precision, what is it?
I am completely dilemma about these things.
Kindly help me to know.
Thanks and regards
Doubts about flaot, double, unsigned and signed
-
- Lieutenant
- Posts: 92
- Joined: Tue Oct 27, 2009 7:50 pm
Re: Doubts about flaot, double, unsigned and signed
In simple terms, the difference is, singed data types can represent negative numbers where as the unsigned ones can only represent positive.1) what is the difference of unsigned and signed.
As both can have same amount of memory eg. unsigned int and signed int have 16 bits(depending upon compiler). then what will be the benefit of signed.
If I explain you a bit more, signed data type reserve the msb (most significant bit) to represent whether the number is positive or negative. If sign bit = 1, then number is negative and it is is zero, number is positive.
Read this post to have a simple explanation on this. https://robot.lk/viewtopic.php?f=47&t=1621
In computing, floating point describes a system for representing numbers that would be too large or too small to be represented as integers. Numbers are in general represented approximately to a fixed number of significant digits and scaled using an exponent. The base for the scaling is normally 2, 10 or 16. The typical number that can be represented exactly is of the form:2) what is the difference between float and double variables?
I have heard that float is a single precision and double is two precision, what is it?
significant digits × baseexponent
The IEEE has standardized the computer representation for binary floating-point numbers in IEEE 754. There are two widely used formats descried in this standard as follows.
- Single precision - This is a binary format that occupies 32 bits (4 bytes) and its significand has a precision of 24 bits (about 7 decimal digits).
- Double precision - This is a binary format that occupies 64 bits (8 bytes) and its significand has a precision of 53 bits (about 16 decimal digits).
Type | Sign | Exponent | Significand | Total bits | Exponent bias | Bits precision |
Single | 1 | 8 | 23 | 32 | 127 | 24 |
Double | 1 | 11 | 52 | 64 | 1023 | 53 |
Introduction to IEEE 754 floating point representation
Floating-point Operations Tutorial
-
- Lieutenant
- Posts: 92
- Joined: Tue Oct 27, 2009 7:50 pm
Re: Doubts about flaot, double, unsigned and signed
But still i have doubt.
Suppose in source file i have declared two variable.
char temp;
unsigned char utemp;
although, i can assign value from 0 to 255 to both variables and these variables store the value i will place,
e.g. temp=200;
utemp=200;
although, these two variables have 8-bit of memory for storage. then why need to declare char as both r same.
second thing, even we can achieve the same result for unsigned char as for char.
e.g. temp=-1;
utemp=-1;
both these variables have same value stored.
I am completely dilemmatic about it.
Can u elaborate it.
Thanks Neo.
Suppose in source file i have declared two variable.
char temp;
unsigned char utemp;
although, i can assign value from 0 to 255 to both variables and these variables store the value i will place,
e.g. temp=200;
utemp=200;
although, these two variables have 8-bit of memory for storage. then why need to declare char as both r same.
second thing, even we can achieve the same result for unsigned char as for char.
e.g. temp=-1;
utemp=-1;
both these variables have same value stored.
I am completely dilemmatic about it.
Can u elaborate it.
Thanks Neo.
Re: Doubts about flaot, double, unsigned and signed
If you do the above, the values on both variables will become as follows.But still i have doubt.
Suppose in source file i have declared two variable.
char temp;
unsigned char utemp;
although, i can assign value from 0 to 255 to both variables and these variables store the value i will place,
e.g. temp=200;
utemp=200;
temp = -56
utemp = 200
the reason is, the range of char (signed char) is from -128 to +127. When you put 200 (1100 1000) to it, it takes it as a negative value since the msb is 1.
unsigned equivalent of 'temp' can be taken by adding 256. (-56 + 256 = 200)
In other words 200 (1100 1000) in signed representation is -56.
Is it clear now?
If you do the above, the values on both variables will become as follows.although, these two variables have 8-bit of memory for storage. then why need to declare char as both r same.
second thing, even we can achieve the same result for unsigned char as for char.
e.g. temp=-1;
utemp=-1;
both these variables have same value stored.
temp = -1
utemp = 255
Similarly, -1 + 256 = 255.
You can try putting 255 to both temp and utemp. temp will become -1 and utemp will become 255.
-
- Lieutenant
- Posts: 92
- Joined: Tue Oct 27, 2009 7:50 pm