Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

unsigned int subtraction...

Status
Not open for further replies.

hhhsssmmm

Member level 1
Joined
May 14, 2009
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,732
Here is a simple question that im confused on...plz can someone answer it...

Im using C18 compiler....

if i use "unsigned int".... and then subtract two integers in such a way that the one which is subtracted is greater
than the one from which im subtracting...forexample...

result = small - big;

this should give me a result that does not care about the -ve sign....am i correct?....so forexample

result = 2 - 4;

the 'result ' value then contains the variable '2'.....ignoring the -ve sign

is this correct?

please can someone correct me.

thank you
Haseeb
 

Hi Haseeb,

Let me tell why you are wrong.
I suppose you are using 16-bit integer types.
Performing 2-4, ( 0000000000000010-0000000000000100 ) the result is 1111111111111110 . (Try the bitwise operation in order to be sure).
That result, interpreted as a signed int would be -2. But as an unsigned, it is 2^16-2=65534.
Regards

Z
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top