When I try to carry out hex multiplication of 16 bits by 16bits using the datatype int64_t, the result displayed is restricted to 32 bits, and a 33rd bit, if present is never displayed, although I am defining the operands as well as result to be 64 bits in length.
Here is the simple code I am using:
#include<stdio.h>
#include <stdint.h>
int main()
{
int64_t a, b, r;
a = 0xabcd;
b = 0xdbca;
r = a * b * 3;
printf("%x", r);
return 0;
}
Result printed out is : ba7fcc46
Expected Result is : 1ba7fcc46
Kindly help me out here.
A popular solution is to use
%llxfor yourprintfformat.llmeanslong long(64-bit long on virtually all systems), although this is not portable.The portable (however, less legible) solution, is to use @anatolyg’s answer, reprinted here: