Friday, 8 May 2015

Finding a Two's complement of a number


void setup(){
int a= 10;
int val = b;
Serial.begin(9600);
a = ~a ; //inverting the number
a = a+B01 ;//addinf the 1 to it
a = a & 0xff;//anding with 0xff to avoid any bit overflow
Serial.print("the 2's complement of ");
Serial.print(val,BIN);
Serial.print("is : ");
Serial.println(a,BIN);
}

void loop(){
}

No comments:

Post a Comment