• Create Account

How many bytes is float?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

12 replies to this topic

#1The C modest god  Banned

Posted 15 February 2004 - 02:09 AM

?

#2billybob  Members

Posted 15 February 2004 - 02:18 AM

sizeof(float)

#3TangentZ  Members

Posted 15 February 2004 - 02:24 AM

Usually 32 bits (4 bytes).

When in doubt, check sizeof(float).

Kami no Itte ga ore ni zettai naru!

#4Blue Phoenix  Members

Posted 15 February 2004 - 02:24 AM

It dependends on the precision.

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

#5jpab  Members

Posted 15 February 2004 - 02:44 AM

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

#6Jingo  Members

Posted 15 February 2004 - 02:57 AM

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]

#7Cedric  Members

Posted 15 February 2004 - 03:05 AM

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

#8antareus  Members

Posted 15 February 2004 - 05:48 AM

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.

#9SabreMan  Members

Posted 16 February 2004 - 12:47 AM

quote:
Original post by The C modest god
?

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

#10superdeveloper  Members

Posted 16 February 2004 - 06:54 AM

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.

#11Jingo  Members

Posted 16 February 2004 - 07:25 AM

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.

#12Anonymous Poster_Anonymous Poster_*  Guests

Posted 16 February 2004 - 07:56 AM

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.

#13Josh Petrie  Moderators

Posted 16 February 2004 - 08:12 AM

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).

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.