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
426 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 167 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 167 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 166 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

815 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now