GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  Programming  >  C

 Print  |  
Question:  sum 0f 2 64 bits using 32 bits

Answer: Hi,
the question is you have cpu that knows to do
computations on 32 bits(unsigned integer).
write a function that find the sum of 2
64 bits numbers
using this cpu?
there is a struct:
typedef struct{
int low;(32 bits)
int high;(32 bits)
}64bit;


July 07, 2008 06:02:05 #2
 amodiahs CRM Expert  Member Since: July 2008    Total Comments: 1 

RE: sum 0f 2 64 bits using 32 bits
 
Hello friends,
Here we need to use a linked list. See, it is already known that CPU doesnot support one single 64bit number hence, first thing is that using normal data types will be useless. So here what we can do is.. Create two linked lists where each one will represent a 64bit # where each node holds a digit of the #. Now traversing these linked lists from tail to head we can keep on adding the digits of two nodes and keep the sum in a new linked list's node taking the carry # for next addition... so like this we can get a new linked list whihc wil contain the sum using which we can then make up a new 64bit structure as u have shown in ur question....

hope this logic helps.....
     

 

Back To Question