2's complement


E

eeh

Hi,

Could anyone give me sample code to calculate 2's complement of an
integer which is n (n<16) bits length?

Thanks!
 
Ad

Advertisements

P

Patricia Shanahan

Lucy said:
int a = 5;
int b = ~a;


That will give the 1's complement, the result of flipping
each bit. You can get the 2's complement in several ways but
the simplest is:

int b = -a;

Patricia
 
Ad

Advertisements

Ad

Advertisements


Top