binary numbers
Tim Roberts
timr at probo.com
Thu Oct 7 07:25:51 CEST 2004
Brad Tilley <bradtilley at gmail.com> wrote:
>
>I Forgot that I'm asking a bunch of CS geeks a
>question about "binary"... I mean "bianry" as in
>the base 2 representation of numbers... One is one
>is one, but one can be represented in different
>bases and still be one... get it?
Not inside a computer, it can't.
>Dec Bin
>1 1
>2 10
>3 11
>4 100
>5 101
>6 110
>...
>How do I pass the binary representation of a
>number to a function???
I'm afraid that it is YOU that does not understand.
Binary is the ONLY representation used inside a computer. When you see the
number "5", it is because a utility function has neatly converted the
binary value in a variable or register to an ASCII format that your human
brain can comprehend. ALL of the following things are equivalent:
x = 15
x = 037
x = 0x0f
x = 6+9
x = len("abcdefghijklmno")
In every case, the variable "x" will contain the binary value 000..0000101,
again because a utility function has neatly converted the human-convenient
forms above into a binary value.
The registry type REG_BINARY does not really mean binary. It means an
arbitrary array of bytes. The only difference between REG_BINARY and
REG_SZ is that a REG_BINARY value can contain zeros, and is displayed
differently in a registry dump.
--
- Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the Python-list
mailing list