wried integer addition

T

tikviva

Hi, I have a question regarding to integer addition.

Here is the problem.

I have an integer, x = 0x00000001
and I also have another integer, y = 0xffffff94

Is there any method to concatenate x & y, so that x = 0x00000194 ?
Thanks for the help. =)

God bless,
tikviva
 
A

Andrey Tarasevich

tikviva said:
...
I have an integer, x = 0x00000001
and I also have another integer, y = 0xffffff94

Is there any method to concatenate x & y, so that x = 0x00000194 ?
...

I don't see how concatenating 0x00000001 and 0xffffff94 might produce
0x00000194. What kind of "concatenation" are you talking about? Why did
you call it "concatenation" in the first place?
 
P

Patrik Stellmann

tikviva said:
Hi, I have a question regarding to integer addition.

Here is the problem.

I have an integer, x = 0x00000001
and I also have another integer, y = 0xffffff94

Is there any method to concatenate x & y, so that x = 0x00000194 ?
Thanks for the help. =)
So you're looking for a function that takes 2 integers and returns
0x00000194 if the input is 0x00000001 and 0xffffff94?

int f(int x, int y)
{
return 0x00000194;
}

Ok, probably not what you were looking for but it's difficult to create
a reasonable function when given only 1 input-output pair...

Maybe you want to take the 1 of x and place at infront of the 94 of y?
Then the function would look like this (i think):
return (x << 8) | (y & 0xFF);
 
K

Karl Heinz Buchegger

Patrik said:
So you're looking for a function that takes 2 integers and returns
0x00000194 if the input is 0x00000001 and 0xffffff94?

int f(int x, int y)
{
return 0x00000194;
}

Ok, probably not what you were looking for but it's difficult to create
a reasonable function when given only 1 input-output pair...

Maybe you want to take the 1 of x and place at infront of the 94 of y?
Then the function would look like this (i think):
return (x << 8) | (y & 0xFF);

You forgot about the 0xfffff part, which has to be masked away (if
your theory of what the function should do holds)

return ( (x & ~0xff) << 8 ) | ( y & 0xff );
 
K

Karl Heinz Buchegger

Karl said:
You forgot about the 0xfffff part, which has to be masked away (if
your theory of what the function should do holds)

return ( (x & ~0xff) << 8 ) | ( y & 0xff );


grr.
That's the problem with bit operations: It is easy to read something
into a source code which is not written there.

Your function was fine.
 
P

Patrik Stellmann

Karl said:
You forgot about the 0xfffff part, which has to be masked away (if
your theory of what the function should do holds)

return ( (x & ~0xff) << 8 ) | ( y & 0xff );

Don't think so! The 0xffffff was only in y, not in x. Your function
would return 0x00000094 because (x & ~0xff) equals 0
 
D

David Harmon

grr.
That's the problem with bit operations: It is easy to read something
into a source code which is not written there.

Perhaps you would prefer

const int rad = 256;
return (x * rad) + (y % rad);
 
G

Geoffrey Mortimer

tikviva said:
Hi, I have a question regarding to integer addition.

Here is the problem.

I have an integer, x = 0x00000001
and I also have another integer, y = 0xffffff94

Is there any method to concatenate x & y, so that x = 0x00000194 ?
Thanks for the help. =)

God bless,
tikviva

Homework?

(x + 1) << 8 + y
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top