answersLogoWhite

0


Best Answer

You should not concern yourself with the internal bit representation of a floating point variable, because that is an implementation specific thing. Writing code that depends on the internal format is certainly not-portable, and possibly dangerous.

That said, many implementations use the IEEE 754-2008 format. The binary32 format has 1 sign bit, 8 exponent bits, and 23+1 mantissa bits for a total of 32 bits.

The sign bit is 0 for positive and 1 for negative.

The exponent is in excess 128 format, which means that it is biased by 128. Simply put, a value of 011111112 means "mantissa x 21".

The mantissa is the binary fraction, i.e. the binary point is to the left of the first bit. It is normalized, meaning that it is left or right shifted until the high order bit is 1, placing its value in the range [0.5, 1.0). Since the high order bit is one, it is left shifted again, and the high order bit is not stored, i.e. it is assumed, giving one more bit of precision. That is why the exponent appears to be excess 127 instead of excess 128.

If the number is actually zero, then all of the bits are zero. There are some reserved bit patterns for special numbers, such as invalid, positive infinity, and negative infinity.

In the Intel format, the order of the bytes are reversed, with the low order mantissa first, and the sign/first exponent byte last.

Again, all of this is an implementation specific thing, and should not be depended on.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How c stores a float value in 4 bytes of float variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why the float takes 4 bytes in turbo c plus plus?

What's your problem with that? It's a (quasi-)standard value for a 'float'.


Can an float value be assigned to int variable?

Yes, an integer can be assigned as a float value.But it get stored as a float value, that is an implicit type conversion occurs during compilation.Smaller data types are convertible to larger data types.eg:float b=12;// an integer constant is assigned to a float variableprintf("%f",b);// when printing b it will print as 12.000000


How do you invoke function result () takes two float argument and returns an integer in c plus plus program?

You can do this by creating a forwarddeclaration of the function. You can call the forward drclared function inside the main to use it.int result(float num1, float num2);intmain(void){int value = result(3.14, 2.74);return (0);}intresult(float num1, float num2){int value = 0;// function codes goes here// you can alter the value of variable 'value'return (value);}The returning value of the 'result()' function is assigned to variable 'value' in 'main()'.


Can a double value be assigned to float variable?

THIS IS FOR JAVA i don't know about anything about other languages yes it can be assignedthe syntax is:int (number) = (float) numberFOR EXAMPLE:int = a;a = (float ) 5.5;if the (float) is not there then in Java it gives an error saying precision loss of data type


What is the difference between datatype and keyword in c?

data type refers to the kind of value that is held by a particular variable. For ex: an int variable contains integer value, a string holds a alpha numeric value etc. variable refers to the name of a value using which we can refer to this value. Ex: public int age = 28; here int is the data type and age is the variable.

Related questions

When you assign the value 5.628 into a float variable how can you avoid getting the decimal truncation warning?

When assigning a literal value, such as 5.628, to a float variable, you can avoid the decimal truncation warning by either using the float form of the constant (float var = 5.628f), typecasting the assignment (float var = (float) 5.628), or by making the variable double (double var = 5.628).


Why the float takes 4 bytes in turbo c plus plus?

What's your problem with that? It's a (quasi-)standard value for a 'float'.


How do you declare a variable with initial value of 20.1234?

float myVariable = 20.1234;


What is the difference between pointer variable and simple variable What are the advantages of pointer variable?

normal variable stores a value of the given datatype where as the pointer variable stores the address of a variable. for example int n=10; int *p; p=&n; here p is a pointer variable and n is a normal variable.p stores the address of n where as n stores an integer value. *p prints the value of n,p prints the address of n.


What is the by default value of globally declaration variable?

int, float: 0 pointer: NULL


Can an float value be assigned to int variable?

Yes, an integer can be assigned as a float value.But it get stored as a float value, that is an implicit type conversion occurs during compilation.Smaller data types are convertible to larger data types.eg:float b=12;// an integer constant is assigned to a float variableprintf("%f",b);// when printing b it will print as 12.000000


How do you invoke function result () takes two float argument and returns an integer in c plus plus program?

You can do this by creating a forwarddeclaration of the function. You can call the forward drclared function inside the main to use it.int result(float num1, float num2);intmain(void){int value = result(3.14, 2.74);return (0);}intresult(float num1, float num2){int value = 0;// function codes goes here// you can alter the value of variable 'value'return (value);}The returning value of the 'result()' function is assigned to variable 'value' in 'main()'.


Can a double value be assigned to float variable?

THIS IS FOR JAVA i don't know about anything about other languages yes it can be assignedthe syntax is:int (number) = (float) numberFOR EXAMPLE:int = a;a = (float ) 5.5;if the (float) is not there then in Java it gives an error saying precision loss of data type


What is the difference between datatype and keyword in c?

data type refers to the kind of value that is held by a particular variable. For ex: an int variable contains integer value, a string holds a alpha numeric value etc. variable refers to the name of a value using which we can refer to this value. Ex: public int age = 28; here int is the data type and age is the variable.


Assign the value of pie ie 3.142 to a variable with requisite data type?

float pi = 3.142; // Note: pi is an irrational number, there is no "exact" value of pi


How many bytes are in a decimal variable?

It depends on the language. In C/C++, decimal values are specified using float, double or long double types. A float is a single precision floating point value that is typically 32-bits in length, however the actual length is implementation dependant. A double is always at least as long as a float while a long double is always at least as long as a double. To determine the actual length at compile time, we use the sizeof() operator.


How you can modify an integer variable value in a function?

with an assignment: variable = value variable += value variable /= -3; ...