Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Given an array of two 32-bit ints, write a function that returns a 64-bit int that contains the value of the two ints concatenated together. (C++

Posted on 2011-02-22
3
Medium Priority
?
434 Views
Last Modified: 2012-08-13
Please tell me how I can do this:

Given an array of two 32-bit ints, write a function that returns a 64-bit int that contains the value of the two ints concatenated together. (C++)

Thanks!
0
Comment
Question by:dshrenik
3 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 668 total points
ID: 34954472
Without giving you a complete solution to your assignment, consider the following (http://www.cppreference.com/wiki/keywords/union):
union LARGE_INTEGER {

  struct {
    unsigned int LowPart;
    int HighPart;
  };

  __int64_t Full64Int;
};

Open in new window

0
 
LVL 32

Assisted Solution

by:phoffric
phoffric earned 668 total points
ID: 34957501
You didn't mention whether element 0 of the array has the LSW or the MSW.

You could set the 64-bit word to the MSW, then shift it to the left (<<) and then add in, or, probably faster, or in (|) the LSW.
0
 
LVL 11

Assisted Solution

by:cup
cup earned 664 total points
ID: 34958691
Alternatively

union LARGE_INT
{
   struct
   {
      unsigned int lo;
      unsigned int hi;
   } int32;
   long long int64;
};

I'm not sure if __int64_t is MS specific or not.  long long will work on both Linux and Windows.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question