By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,032 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Arithmatic in c

P: n/a
Hi All,

I want to do arithmetic in c like below:

A Op B = C
1. 0x1100 Op 0x1000 = 0x0100
2. 0x2300 Op 0x1000 = 0x0300
3. 0x1000 Op ox1000 = 0x1000

I know if I do A%B then I can get C. But it is true only for case 1 and 2. But in case 3 A%B will give 0x0000.

I want to perform same operation on A and B to get C in all cases.

If it is not possible by single operator i don't mind doing multiple operations on A and B to get C.

Please help me in this.

Hope my question make sense.

Sep 28 '10 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 5K+
P: 9,197
0x1000 % 0x1000 = 0x1000

This is correct since the remainder of 0x1000/0x1000 is

All of your cases work using the % operator.
Sep 28 '10 #2

Expert 100+
P: 2,396
x % x = 0 for (x != 0).

Where did this problem come from? Are you sure you copied case 3 accurately?
Sep 28 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.