Announcement

Collapse
No announcement yet.

How to multiply 2 signed 16bit and put into long value.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to multiply 2 signed 16bit and put into long value.

    currently you can only do umul_1616(). This is for unsigned. how can you do signed and that into a long value.

    In the long value, it is an arrary of 2 16bit word. Is the first one the high word and the 2nd one the low word?

  • #2
    Hello,

    You could use the float functions to multiply 2 16 bit signed values. You can find the Floats section on page 414 http://www.4dsystems.com.au/productp...ions_R_2_0.pdf

    I hope this helps

    Best regards

    Paul

    Comment


    • #3
      Right. This would be
      converting 2 signed ints to floats
      multiplying the floats
      converting the floats back to ints.

      Since there an unsign umul function, is there a signed function?

      Comment


      • #4
        Hi,

        A float can be set using a floatstring using this command flt_VAL(&fresult, numstring) eg

        flt_VAL(&fresult, "12345.67");

        and you can also print it using flt_PRINT(&fvalue, formatstring)

        There isn't a signed version of the umul function.

        Best regards

        Paul

        Comment


        • #5
          Thank you very much

          Comment


          • #6
            You could first convert each Signed value to an unsigned value (noting the sign of each), do the umul_1616(), and then convert that back to a signed value based on the signs of the original two numbers. You'd need to check for an overflow condition, as a unsigned val in 16 bits can be bigger than a signed value can be represented in 16 bits.

            Comment

            Working...
            X