Crossing, everyone, from today onwards, we talk about the large-scale couplet science fiction: C Chestnut, that is, C language examples. Gossip Hugh,
Words return to the positive turn. Let's talk C chestnuts together!
Crossing, the last time we were talking about the example of generating a random number, this time we say the example is: the binary conversion. When it comes to the system estimate, everyone
Are not unfamiliar, the computer in the binary system has binary, octal, decimal, hexadecimal.
What we're going to talk about today is how decimal is converted into binary, octal, and hexadecimal. Here I put the procedure and algorithm ideas to write the program
Write it out for everyone's reference.
1. Get the values that the user wants to convert and think about the binary of the conversion. Here to check if the input is correct. This is the embodiment of the robustness of the program.
2. Different conversions are made according to the different input of the user. In the code, I encapsulate the conversion process into a function.
3. Output the converted results. The output converted results are also encapsulated as a function.
Crossing, let's talk about how to make a binary conversion, that is, the content of the conversion function.
1. Use the converted numerical mode to convert the binary, and save the result of the mold. For example, the converted value is 9 and the conversion is 2.
So the result of the =9%2. This step is executed several times, as determined by step 2. Turn the results of each execution from left to right
The result of converting into a row is the conversion. Use an array in your program to save the results.
2. Divide the converted value by the conversion, and determine whether the quotient is 0. If you do not repeat steps 1 and 2 for 0 until the quotient equals 0.
Crossing, we're done with the conversion function, let's talk about the function of the output input conversion result.
1. The output is the opposite of the order in which the results are saved in the conversion transformation function. Save is in the direction of the array head to tail, when output
is the direction of the head along the end of the array. Two in the opposite direction.
2. The output of the 16 binary contains a-f these characters, so they are specifically converted.
Crossing, the text does not write code, the detailed code put in my resources, you can click the link to download the use.
You crossing, we're going to talk about this in the case of the conversion. I want to know what the following example, and listen to tell.
A talk C Chestnut bar (seventh time: C-language example---binary conversion)