Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC question about DATA directive — Parallax Forums

PBASIC question about DATA directive

connolly113connolly113 Posts: 8
edited 2008-04-15 12:27 in BASIC Stamp
I have a question about the DATA directive·in the pbasic syntax guide, one of the examples given is pasted below. I cannot figure
out where the "101" and "4" come from, can someone explain this to me

thks.
(BS2pe,PBASIC 2.5)



DATA········· Word 1125

The directive above will automatically break the
word-size value into two bytes and store them into two
sequential EEPROM locations (the low-byte first,
followed by the high-byte, or "Little Endian"). In
this case, the low-byte is 101 and the high byte is 4
and they will be stored in locations 0 and 1, respectively.


Comments

  • rockybulwinklerockybulwinkle Posts: 36
    edited 2008-04-15 03:45
    Here is what I figured out:
    1125 (decimal)=0000010001100101 (binary)
    101 (decimal)=01100101 (binary)
    4 (decimal)=00000100 (binary)
    so, if you stick them together, you get 00000100 01100101 which is 1125 in decimal.
    its like reading the two bytes that make the word independently.
    I hope I helped some! wink.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are 10 kinds of people in the world;
    those who understand binary and those who don't.
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-04-15 12:27
    1125 = % 0000 0100 0110 0101 [noparse][[/noparse]two bytes = 1 word, we used to call two bytes a "chomp"]

    That gets broken up into two bytes.

    The MSB gets stored in·an address as·% 0000 0100···(4)
    The LSB gets stored in an address as % 0110 0101·(101)

    (4 x 256) + (1·x 101) = 1125
    ·········· 1024 + 101 = 1125
    ················ 1125 = 1125
Sign In or Register to comment.