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
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 410 of 437    Print  
sum 0f 2 64 bits using 32 bits
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;



  
Total Answers and Comments: 2 Last Update: July 24, 2008     Asked by: eminemm 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
July 06, 2008 07:15:30   #1  
brijux Member Since: June 2008   Contribution: 5    

RE: sum 0f 2 64 bits using 32 bits
I am also looking for the answer of the same. I know how to do this in assembly, but I dont know how it works in C. I will try to explain how I do it in assembly, may be there is some same method for C.

Suppose be have two 64 bits number in variable A and B. The variable is subdevided in to AH:AL and BH:BL. (AL,AH,BL,BH are all 32 bits). Answer is stored in C (CH:CL)

1) so now first add AL and BL. so CL = AL+BL
2) if there is any carry than add it to higher byte. if no carry thn just add higher bytes.
CH = AH + BH + Carry(if any)

So your answer is in CH:CL....

We can check for the carry using the carry flag in assembly language. But how do you know if there is any carry or overflow in C??

 
Is this answer useful? Yes | No
July 24, 2008 06:02:05   #2  
amodiahs Member Since: July 2008   Contribution: 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.....

 
Is this answer useful? Yes | No

 Related Questions

Floating-point numbers are the “black art” of computer programming. One reason why this is so is that there is no optimal way to represent an arbitrary number. The Institute of Electrical 
Latest Answer : A program running in the database that can take complex actions based on the inputs you send it. Using a stored procedure is faster than doing the same work on a client, because the program runs right inside the database server. ...

For integral types, on a machine that uses two’s complement arithmetic (which is just about any machine you’re likely to use), a signed type can hold numbers from –2(number of bits – 
Latest Answer : Hi,a simple code snipet show how to determin the maximum value that an integer can  haveunsigned int x = 0;--x;now check the  value of x. This would contain maximum value that an interger can have.now you can determine the values containing ...

Both the malloc() and the calloc() functions are used to allocate dynamic memory. Each operates slightly different from the other. malloc() takes a size and returns a pointer to a chunk of memory at least 

As described at the beginning of this chapter, some compilers for PC compatibles use two types of pointers. near pointers are 16 bits long and can address a 64KB range. far pointers are 32 bits long and 
Latest Answer : atthe time of 8086 , the processor operate in real modebt after that as more processor develop then there are two type of mode.2nd one is protected mode.in real mode the processor canuse only 1mb bt in protected mode one can use memory more then 1mb.as ...

fff0Explanation :-1 is internally represented as all 1's. When left shifted four times the least significant 4 bits are filled with 0's.The %x format specifier specifies that the integer value 
Latest Answer : Depending on the machine implementation it will result in FFFFFF0 (for 32bit ) or FFF0 (16 bit ) ...
Read Answers (1) | Asked by : Beena

How to swap low-order byte & the high order byte in an integer without using temporary variable?for ex: int a=20;It is represented in bits as (i.e 16 bit format)since integer is of two bytes00000000 00010100i want the answer as00010100 00000000ie 5120 as the answer
Read Answers (5) | Asked by : preetham

Hi,the question is you have cpu that knows to docomputations 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 
Latest Answer : 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 ...
Read Answers (2) | Asked by : eminemm


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

SQL Programming

SQL Programming Overview Anybody who has done something for a long time has probably wanted to change how things work at some point or another. A worker at a mill might have found a more efficient way of cutting logs, or a mathematics teacher might have had a hand in changing a school’s al
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

WinRunner Programming Concepts

If you want to create WinRunner scripts that are highly efficient, there are important programming concepts that you will want to become familiar with. Understanding these concepts will provide you with a large number of key benefits. In addition to understanding these concepts, you must also learn
 

Programming Languages Certification

IT Certification programs have several options that will offer you the best knowledge.  By learning everything that you need to know about information technology you will be able to open new doors to your career and personal business desires.  IT Certification offers several vari
 

Neuro-linguistic Programming Methods

Neuro linguistic Programming Methods There are several methods used for performing Neuro linguistic Programming on an individual for obtaining insights into the psyche of the person in order to correct to modify certain patterns of behavior These techniques are also used for Neuro linguistic trainin
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

The Difficult Past of Neuro-linguistic programming

The Difficult Past of Neuro linguistic programming Neuro linguistic programming has had a rocky past with a number of lawsuits rivalry unsystematic development and intermittent progress During the 1980s the two founders separated after the lawsuit filed by Bandler Bandler went on to file several law
 

History of Neuro Linguistic Programming (NLP)

History of Neuro linguistic programming Neuro Linguistic Programming NLP is a system co founded by John Grinder and Richard Bandler for bringing about personal development in any individual by interpreting and translating the human perception experience beliefs and language It was developed in early
 

Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape