Archived

This topic is now archived and is closed to further replies.

How many bytes is float?

This topic is 5083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

quote:
Original post by Blue Phoenix
It dependends on the precision.

It can be 16-bit (float) or 32-bit (double). Anyone correct me if i''m wrong.

As others have said, the only definitive answer is sizeof(float). But I believe that it''s often 32-bit for float, and 64-bit for double.

John B

Share this post


Link to post
Share on other sites
sizeof() only gives you the size of the object in terms of char, sizeof(char) is always one. You should check
std::numeric_limits<char>::digits  
to work out the number of bits in a char

[edited by - Jingo on February 15, 2004 9:58:28 AM]

Share this post


Link to post
Share on other sites
DUDE! You have 6 questions shown on the page of this forum RIGHT NOW, and 4/6 could have been easily answered by a forum search, or by using Google Groups! And 1 of the remaining two was a problem whose solution you found yourself (one has to wonder if you had really tried enough before posting).

The sum of the views for those 6 questions is 448! That''s a lot of time spent on reading trivial questions.

Final advice: read the C++ FAQ Lite. It''s a good investment.

Cédric

Share this post


Link to post
Share on other sites
quote:
Original post by Cedric
DUDE! You have 6 questions shown on the page of this forum RIGHT NOW, and 4/6 could have been easily answered by a forum search, or by using Google Groups! And 1 of the remaining two was a problem whose solution you found yourself (one has to wonder if you had really tried enough before posting).

The sum of the views for those 6 questions is 448! That''s a lot of time spent on reading trivial questions.

Final advice: read the C++ FAQ Lite. It''s a good investment.

Cédric

You sound like me.

Share this post


Link to post
Share on other sites
quote:
Original post by The C modest god
?

Do we have twenty questions to guess which language and platform you''re using?

Share this post


Link to post
Share on other sites
Be careful all: in java, a char is 2 bytes.

Java of course has a "byte" keyword to represent the 8 bit entity. Java focuses on (unicode, etc) 16 bit versions of characters, "chars"...

But yes, in C/C++, a byte is 8 bits wide.

Share this post


Link to post
Share on other sites
quote:
Original post by superdeveloper
But yes, in C/C++, a byte is 8 bits wide.



No, the number of bits in a C++ byte is undefined.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by Jingo
No, the number of bits in a C++ byte is undefined.
You mean the number of bits in a C++ char? Because byte is defined to be 8 bits, much like nibble is defined as 4 bits, independ of the platform or the language.

Share this post


Link to post
Share on other sites
quote:

You mean the number of bits in a C++ char? Because byte is defined to be 8 bits, much like nibble is defined as 4 bits, independ of the platform or the language.



In C++ a char is defined to be one byte. A byte is not neccessarily 8-bits, although for all intents and purposes you are probably safe assuming that nowadays. Likewise, a nybble is defined to be half a byte, not neccessarily four bits.

In any case, I think we''re all agreed that the answer to the OP is sizeof(float), at least in C++.

(I don''t really know if there is an "official" definations for byte, nybble, et cetera, so I''m basically going off of foldoc.org''s entries for the same).

Share this post


Link to post
Share on other sites