473,320 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

wried integer addition

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
Jul 22 '05 #1
7 1602
tikviva wrote:
...
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?

--
Best regards,
Andrey Tarasevich

Jul 22 '05 #2
tikviva wrote:
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);

Jul 22 '05 #3
Patrik Stellmann wrote:

tikviva wrote:
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);


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 );

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #4
Karl Heinz Buchegger wrote:

Patrik Stellmann wrote:

tikviva wrote:
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);


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.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #5


Karl Heinz Buchegger wrote:
Patrik Stellmann wrote:
tikviva wrote:

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);

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

Jul 22 '05 #6
On Fri, 20 Feb 2004 10:08:53 +0100 in comp.lang.c++, Karl Heinz
Buchegger <kb******@gascad.at> was alleged to have written:
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.


Perhaps you would prefer

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

Jul 22 '05 #7

"tikviva" <ti*****@yahoo.com> wrote in message
news:4b*************************@posting.google.co m...
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
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Alex Vinokur | last post by:
Consider the following statement: n+i, where i = 1 or 0. Is there more fast method for computing n+i than direct computing that sum? -- Alex Vinokur email: alex DOT vinokur AT gmail DOT...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
20
by: GS | last post by:
The stdint.h header definition mentions five integer categories, 1) exact width, eg., int32_t 2) at least as wide as, eg., int_least32_t 3) as fast as possible but at least as wide as, eg.,...
16
by: archilleswaterland | last post by:
Hi, I am using a compiler that does not support long int (32 bits) so I am using 2 int's to do the work my problem int a; int b; int c;
25
by: junky_fellow | last post by:
Is there any way by which the overflow during addition of two integers may be detected ? eg. suppose we have three unsigned integers, a ,b, c. we are doing a check like if ((a +b) > c) do...
40
by: Robert Seacord | last post by:
The CERT/CC has released a beta version of a secure integer library for the C Programming Language. The library is available for download from the CERT/CC Secure Coding Initiative web page at:...
5
by: Mike | last post by:
Hello All, Please, if anyone can point me to the problem, I'd sure appreciate it! I am very new to VB programming and not a programmer to begin with. This is part of a Visual Basic 2005 Express...
11
by: lovecreatesbea... | last post by:
I read some old posts, they did this task in very different ways. How is the following one? Thank you for your time. /...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.