top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

Float with long variable and implementation of addition?

+2 votes
42 views

Say my CPU don't have support for the float variables and uses a long type integer (32 bit)

The leftmost bit (MSB) is the sign (0 means +, 1 means -) - lets call it S
The next 8 bits are the exponent - lets call it E.
The rest bits (23) are the Mantissa (i.e the fraction) - lets call it M.
The number is calculated by this formula: (-1)^S * M * (2^E)

Now we need a function

unsigned long add(unsigned long float1, unsigned long float2)

which gets 2 numbers of the representation above, and returns the result of the addition of them (as described above).

posted Nov 3, 2014 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

Assumption:
The input strings will contain only numeric digits
The input strings can be of any large lengths
The lengths of the two input string need not be the same
The input strings will represent only positive numbers
Example

If input strings are “1234” and “56”, the output string should be “1290”
If input strings are “56” and “1234”, the output string should be “1290”
If input strings are “123456732128989543219” and “987612673489652”, the output string should be “123457719741663032871”

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...