Dark Horse programmer-C language open-door chip memory analysis, dark horse programmer open-door

Source: Internet
Author: User

Dark Horse programmer-C language open-door chip memory analysis, dark horse programmer open-door

IOS training, iOS study --------- technical blog, hope to communicate with you! ------------

 

I. Summary of various hexadecimal formats

1. Binary
(1) in C language, the binary starts with 0 B and the output binary format does not have a fixed format. udfs can be defined as follows: # include <stdio. h>

Int main ()
{
Void printfBinary (int );

PrintfBinary (20 );

Return 0;
}

Void printfBinary (int n)
{
Int bits = sizeof (int) * 8; // calculates the number of bytes occupied by the integer variable.
While (bits --> 0 ){

// The binary form of n moves bits byte to the right, and then bitwise AND operation is performed on the same 1. The original value is retained for printing.
Printf ("% d", n> bits & 1 );

If (bits % 4 = 0 ){
Printf ("");
}
}
}

2. Gossip
The octal value starts with 0 and uses % o to output an integer without a symbol. The hexadecimal value is 3.
The hexadecimal format starts with 0x and uses % x to output an integer.
4. Decimal

In C language, except for the hexadecimal numbers in the preceding three formats, common data is represented in decimal. Use % d to output signed integers, and % u to output unsigned integers

2. How to swap two variable values

1. Use the intermediate variable value method for interchange
Assume that the values of two variables are int a = 5, B = 6, and another variable is used for exchange. The specific code is as follows:

Void swap ()
{
Int a = 5, B = 6;

Int c = a; // Add the value of a to c.
A = B;
B = c;
}

 

2. Direct Exchange

  1. A = B-a; // The difference between a and B.
  2. B = B-a; // The original value of B is changed to.
  3. A = B + a; // The original value of a is changed to B

3. Exchange Based on bitwise OR operations, and use the bitwise OR calculation law, that is, a ^ B ^ a = B
  1. A = a ^ B;
  2. B = a ^ B;
  3. A = a ^ B;

4. The exchange of two numbers reminds me of an interview question, as shown below:   There are two cups, A = 5 ml and B = 3 ml respectively. Ask how to get 4 ml of water. The water is infinite, but you cannot use another container, there are two methods for this question:
(1) first, pour A filled with water into B, then the B container is poured out, the remaining A = 2 is then poured into B, and then filled with A and then poured into B, at this time, A = 4 ml;
(2) first fill B in A, then fill B in A, B is 1 ml, pour A, B into A, then, A = 4 ml can be obtained after B is filled and then A is poured into;

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.