Shop OBEX P1 Docs P2 Docs Learn Events
Aliases and Modifiers — Parallax Forums

Aliases and Modifiers

SteveDSteveD Posts: 64
edited 2006-10-19 02:56 in BASIC Stamp
My understanding according to the Syntax Manual concerning the symbols ".Byte1" and ".Byte0" are identical to ".HIGHBYTE" and ".LOWBYTE."· Is this correct?

Thanks
Steve

Comments

  • jonwjonw Posts: 67
    edited 2006-10-19 00:10
    · Thats the way I read it too·Steve.

    ···· jonw
  • SteveDSteveD Posts: 64
    edited 2006-10-19 00:44
    My reason for asking is part of the code for the DS1620 High Resolution example in the Stamp Works book.
    tempIn = tempIn >> 1 ' remove half degree bit

    ******tempIn.BYTE1 = -tempIn.BIT7 ' extend sign bit*********

    tC = tempIn * 100 ' convert to 100ths
    tC = tC - 25 + (slope - cRem * 100 / slope) ' fix fractional temp

    ******IF (tC.BIT15 = 0) THEN***********

    tF = tC */ $01CC + 3200 ' convert pos C to Fahr
    ELSE
    tF = 3200 - ((ABS tC) */ $01CC) ' convert neg C to Fahr
    ENDIF

    I am not seeing how this line " tempIn.BYTE1 = -tempIn.BIT7 " moves anything to tC.BIT.15. I could see it putting in tC.BIT.8.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-19 01:52
    Steve,

    The line
    tempIn.byte1 = -tempIn.bit7
    does what it says: extends the sign bit. If that bit happens to be a 1, then all the bits in tempIn.byte1 become ones.

    Suppose the temperature is +2 degrees. The the DS1620 returns a 9 bit raw value of %000000010.

    But if the temperature is -2, then the DS1620 returns a 9 bit raw value of %111111110. In 16 bit twos complement, the correct binary for -2 is, %1111111111111110. The ninth bit from the DS1620 thus has to be "extended" to fill all the bits. So, tC bit 15 is in fact affected if the original value is negative.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • SteveDSteveD Posts: 64
    edited 2006-10-19 02:56
    Thank you for the wonderful explanation Tracy. It makes perfect sense now.
Sign In or Register to comment.