"Spliting" data into two variables

1
2
3
4
5
6
7
8
#include <iostream>
using namespace std;
int value, x, y;
int main()
{
cout << "Enter a 32bit value: ";
cin >> value;
}

Now I want to move the first 16bits of the value to variable x and the last 16bits to variable y. So if I enter 12345678 x = 1234 and y = 5678

Any way to do this?
This isnt so difficult. All you need t use is % operator

1
2
3
4
5
6
// perform a check to see if value is 32-bit
// else retuen an error

x = value%10000;  // supossing that you want to store the value in x and y

y = value/10000;

Last edited on
@crazzyguy101 I think he is talking about the hex values.

@TH 113

1
2
3
4
5
6
7
unsigned long value;

// input value

unsigned long x = (value >> 16) & 0xFFFF; // Most significant word
unsigned long y = value & 0xFFFF; // Least significant word
@crazzyguy101 I think he is talking about the hex values.


Oh is that the case ? I am sorry.

then i suppose the values in decimal will be value%(2^16) and value/(2^16), i guess...
Topic archived. No new replies allowed.