Can someone please explain the operator */


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2011
    Location
    St. Louis, MO
    Posts
    13

    Default Can someone please explain the operator */

    Could someone explain the */ operator to me. Im using the MAX6675 for a determining the temperature. The temperature is stored as a 12bit value. The example found here uses:

    Code:
    shiftin thdata,thclk,0,[result\16] ' get data from MAX6675
    
    TempC=result>>3*/640  ' for MAX6675 +/- 0.1 degC, up to 1023.7
    TempC is a WORD variable.

    Then when the program displays the temperature it first divides by 10. ie.

    Code:
    debug dec THC/10,".",dec1 TempC
    What effect does the */ have on the result variable? How does "Middle 16bit Multiplication" work?

    Thanks
    "Reality is merely an illusion, albeit a very persistent one." , Albert Einstein

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,520


    Did you find this post helpful? Yes | No

    Default Re: Can someone please explain the operator */

    Hi,
    It's like multiplying by 1/256 units. In other words the result = x */ 640 is the same as saying result = x * 640 / 256.

    What happens internally is a 16*16bit multiplication which results in a 32bit result but the the middle 16bits are returned as the result and the 8 lowest significant bits are discarded.

    Let's try this:
    result = 100 */ 640
    Internally this results in a value of 64000, which, when looked at as 32bits, are 00000000 00000000 11111010 00000000
    Then the middle 16bits are returned and assigned to the variable result, ie 00000000 11111010 which in decimal is 250.
    100*640/256=250

    Put yet another way, let's say you need to multiply a value by 3.64 (100*3.64=364). The value to use with the */ operator is first calculated as 3.64*256=932 (rounded).
    result = 100*/932
    Internally you'll get 100*932=93200 which is then "divided" by 256 (simply by returning the middle 16 bits of the 32bit intermediate result) before it's returned to you. 93200/256=364 which is what we'd expect.

    /Henrik.

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts