Source code, complement code, reverse code (C language source code), back code
# Include <stdio. h>
# Define N 8 // here you need 8 digits
Int main (int argc, const char * argv []) {
Int binary [8]; // used to store the final acquired complement code
Int a = 0; // the value to be processed
Int a1 = 0; // Save the value of
Int m = 0; // used to store temporary values
Printf ("Enter the value of the number of binary complement codes to be converted: \ n ");
Scanf ("% d", & );
A1 =;
If (a = 0 ){
For (int I = 0; I <N; I ++ ){
Binary [I] = 0;
}
} Else if (a <0) {// The negative part starts
Binary [0] = 1;
A =-;
// Start the source code Part
For (int I = N-1; I> 0; I --){
Binary [I] = a % 2;
A = a/2;
If (a <1 ){
M = I;
Break;
}
} // The source code is partially completed.
Printf ("% d original code value:", a1 );
For (int I = 0; I <N; I ++ ){
Printf ("% d", binary [I]);
}
Printf ("\ n ");
For (int I = m; I <N; I ++) {// negative number returns the inverse part, and the first sign bit remains unchanged.
If (binary [I] = 0 ){
Binary [I] = 1;
}
Else binary [I] = 0;
}
Binary [N-1] = binary [N-1] + 1;
For (int I = N-1; I> 0; I --){
If (binary [I]> 1 ){
Binary [I] = 0;
Binary [I-1] = binary [I-1] + 1;
If (binary [I-1] <2 ){
Break;
}
}
}
// The negative part ends.
} Else {
Binary [0] = 0;
For (int I = N-1; I> 0; I --){
Binary [I] = a % 2;
A = a/2;
If (a <1 ){
M = I;
Break;
}
}
For (int I = 1; I <m; I ++ ){
Binary [I] = 0;
}
Printf ("% d original code value:", a1 );
For (int I = 0; I <N; I ++ ){
Printf ("% d", binary [I]);
}
Printf ("\ n ");
}
Printf ("% d:", a1 );
For (int I = 0; I <N; I ++ ){
Printf ("% d", binary [I]);
}
Printf ("\ n ");
Return 0;
}
Running result: