Shop OBEX P1 Docs P2 Docs Learn Events
New guy has one more question. — Parallax Forums

New guy has one more question.

ArchiverArchiver Posts: 46,084
edited 2003-07-02 05:34 in General Discussion
Thank your Tracy. I did see the dig commands but I was concerened
the "1234" would be stored im the CPU's memory as the hex number 4D2.
Why is ANGLE an interger and not a HEX number?

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-07-02 05:34
    >Thank your Tracy. I did see the dig commands but I was concerened
    >the "1234" would be stored im the CPU's memory as the hex number 4D2.
    >Why is ANGLE an interger and not a HEX number?

    The internal representation of the number 1234 inside the Stamp's
    binary brain is
    010011010010
    If you divide that up into groups of 4 bits, you get
    0100 1101 0010
    4 D 2
    So, yes, both answers are right. It is stored as a binary integer,
    but it is also convenient to talk about it in shorthand as HEX.
    x var word
    x = 1234
    debug HEX x,cr ' prints 4D2

    debug DEC x,cr ' prints 1234

    debug BIN x, cr ' prints 10011010010

    for i=3 to 0 ' note the order
    debug x dig i + 48
    next ' also prints 1234, +48 converts to ascii numerals

    Numbers can be shown in different bases upon output.

    One thing you do have to worry about is BCD. It would be possible to
    represent 1234 in the binary brain of the Stamp as:
    0001 0010 0011 0100
    1 2 3 4

    x = $1234 ' BCD is like HEX without ABCDEF
    debug HEX x ' prints 1234
    debug DEC x ' prints 4660, no meaning really
    debug BIN x ' prints 1001000110100
    for i=3 to 0
    debug x.nib0(i) + 48 ' different from the above
    next ' also prints 1234

    There are lots of ways to represent numbers in a computer memory.
    The standard binary way is the most convenient for calculations.

    -- Tracy
Sign In or Register to comment.