On 2009-11-16, cfaqs c <> wrote:
> If the size is 4 bytes, how is a small number, say 6, stored in the
> machine. 6 in binary is 110. So all the prefix bits in the 4 bytes of
> storage is padded with zero is it?
It's not padding, it's part of the representation of the number. But yes,
it's all 4 bytes. You can't change the size on the fly. (There are
languages in which you can, but that's sort of different.)
> Also, how is a negative number stored? I mean i want to know it's
> binary representation
It depends on your system. Different systems do it differently. The
most common systems are called "1s complement", "2s complement", and
"sign/magnitude.
The risk you face here is that you seem to be trying much too hard to
"figure out what really happens" -- if you do that really early on, it's
easy to get stuck on expecting every computer you ever encounter to be just
like the one you learned on, and since that's not likely to be the case,
it can screw you over badly.
Start out by being aware that these answers may change sometimes, and it'll
be less likely to bite you badly later.
-s
--
Copyright 2009, all wrongs reversed. Peter Seebach /
usenet-
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!