Source code, complement code, reverse code (C language source code), back code

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.