Hi all
How would i go about creating a function to add 2 16bit and 2 32bit integers together and return a long integer result. i dont even know where to start. Please help
Hi all
How would i go about creating a function to add 2 16bit and 2 32bit integers together and return a long integer result. i dont even know where to start. Please help
I guess the above is what you mean? There is no guarentee that sizeof(short) = 16 bits or sizeof(long) = 32 bits, but they are that size on *nix and MS-windows.Code:long foo(short a, short b, long c, long d) { return a+b+c+d; }
Be careful of overflows. If the result ever becomes larger than 2^32 (or whatever a long is on your system (the ^ is power-of, not XOR in this case)) then your result will be undefined.
If you understand what you're doing, you're not learning anything.