fixed point subtraction for two's complement data -


i have real data. example +2 , -3. these data represented in two's complement fixed point 4 bit binary value msb represents sign bit , number of fractional bit zero.

so +2 = 0010

-3 = 1101 

addition of 2 numbers (+2) + (-3)=-1

(0010)+(1101)=(1111) 

but in case of subtraction (+2)-(-3) should do?

is needed take two's complement of 1101 (-3) again , add 0010?

you can evaluate -(-3) in binary , sums other values.

with two's complement, evaluate opposite of number pretty simple: apply not binary operation every digits except less significant bit. equation below uses tilde rapresent not operation of single bit , assumed deal integer rapresented n bits (n = 4 in example):

enter image description here

in example (with informal notation): -(-3) = -(1101) = 0011


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -