James Kanze
10/31/2008 10:34:00 AM
On Oct 30, 8:14 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> Richard Herring wrote:
> > A value is just a value, it isn't "binary" any more than it
> > is "hexadecimal".
> True, but it's difficult to talk about values and their
> storage when the terminology is so confusing.
> "Hexadecimal" refers quite unambiguously to the (usually
> ascii) representation of a numerical value (in base 16). The
> term "binary" is more complicated.
> In theory when you say "the number is stored in binary" it
> might refer to one of two things:
> 1) It's stored in base-2 representation. That is, the number
> is stored by writing a combination of the two characters '0'
> and '1'.
That is, actually, what is required by the C++ standard.
Of course, since only two characters are involved, a character
encoding using just one bit (rather than the usual 7, 8 or more)
is sufficient, and used by all of the implementations I've ever
encountered.
(Sort of a half :-). Just thought I'd add to the confusion, for
the fun of it.)
> 2) It's stored in the same way as it's stored in memory, in
> other words, as a series of octets. In other words, it's
> stored in "raw" format, without any conversion or
> representation in ascii.
I like the word "raw". Or "machine" or "hardware" representation.
The C++ standard requires this to be a pure binary
representation (and I don't think the intent is to require
ASCII).
Of course, all of the standard requirements are "as if"; an
implementation can use base 10, as long as it implements &, |, ^
and ~ in a manner that they behave "as if" the representation
were base 2.
> Thus the term "binary" is used with two different meanings: In
> some contexts it talks about base-2 (ascii) representation, in
> other contexts it talks about raw, unconverted byte values
> (eg. when saying "open the file in binary mode). These two
> things have basically nothing to do with each other, except
> that they share the name "binary".
And that they are both demonstrably base 2. (Consider the
behavior of |, &, ^ and ~.)
> Maybe this is the reason why it seems that some people get
> even more confused and think "hexadecimal" refers to what
> usually is meant with "binary" (in the second meaning).
Since most modern machines are byte oriented, maybe we should
call machine format base 256.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34