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
430 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

687 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