Shop OBEX P1 Docs P2 Docs Learn Events
Question about Stamp lesson — Parallax Forums

Question about Stamp lesson

Alex41Alex41 Posts: 112
edited 2007-06-13 22:38 in Learn with BlocklyProp
Hello,

I have a question about a lesson in the "What's a Microcontroller?" with the BS2-IC. The version is 2.2.

My question is about the lesson on Page 155.
I understand the concept of scaling and offset, what I don't understand is that the fractional value is multiplied by 256. Why 256? Is there a reason for this specific number? This isn't explained in the book. Or is 256 just a random number that was chosen?

Thanks for any help.
Alex

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-13 02:18
    256 is 2 to the 8th power. A byte represents 256 different values (0 to 255). When you multiply a value by 256, you shift it left by 8 bits.

    In the case of the lesson, the "binary point" is being placed between the two bytes of a 16 bit value with the most significant byte containing the integer part and the least significant byte containing the binary fraction.
  • Alex41Alex41 Posts: 112
    edited 2007-06-13 15:50
    Thanks for the answer.

    I partly understand what you are saying. My confusion is that .724 was multiplied by 256 resulting in 185. Wouldn't you want to use a number that would have 256 as the result of the multiplication?

    Alex
  • edited 2007-06-13 21:35
    Hi Alex41,

    I answered a similar question in the BASIC Stamps forum the other day. Check out my 6/1/2007 11:53 AM (GMT -7) post here:

    http://forums.parallax.com/showthread.php?p=653664

    Andy

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-06-13 22:38
    Alex,
    What you have is 185/256. Try doing that on a calculator or in long hand and you'll see that it's the same (approximately) as 0.724.
Sign In or Register to comment.