Pages: [1]   Go Down
Author Topic: Is it possible to do 32 * 32 bit multiplication on arduino due.  (Read 405 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 46
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

since the int or long data type in due can support till a maximum of 32 bits. So will it be possible to do a 32 * 32 bit multiplication. If possible then how can we get the output.
Logged

USA, East Coast
Offline Offline
Newbie
*
Karma: 0
Posts: 34
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, it is possible.  I just did it in the example below.  However, like you, I am learning how to use the Due.

Code:
  char outBuf[60], rrBytes[17];
  int k;
  unsigned long long rr;
  unsigned long xx = 0x0001FFFF;
  unsigned long yy = 0x00300000;
  rr = (unsigned long long)xx * yy;
  for( k=0; k<8; k++)
    sprintf( &rrBytes[k*2], "%02X", ((unsigned char *)&rr) [k]);
  rrBytes[16] = '\0';
 
  sprintf( outBuf, "\n  %08X * %08X = %llx  rrBytes[0..7]= %s", xx, yy, rr, rrBytes);
  Serial.println(outBuf);

This will produce the output line below:
  0001FFFF * 00300000 = 5fffd00000  rrBytes[0..7]= 0000D0FF5F000000

Note the internal ordering of the result rr in rrBytes[0..7].  It is the Intel type ordering.
Logged

Pages: [1]   Go Up
Jump to: