C Memory Analysis in the language
One, the binary
we need to know. 4 medium: Binary, octal, decimal, hexadecimal
#include <stdio.h>
int main ()
{
// By default is the decimal
Intnumber = 12;
// Binary
intnumber2=0b1100;
// octal
Intnumber3 = 014;
// hexadecimal
Intnumber = 0xc;
Return0;
}
Printf types that are output in a different binary form:
%d usually outputs an integer in decimal
%o usually outputs an integer in octal
%x usually outputs an integer in hexadecimal
%u output integers as unsigned decimal
%c Output one character
%s output one or more strings
%f outputs a single-double-degree value in decimal form, by default 6 bit
%e shift the standard exponential form output single double precision number, the number of small water level is 6 bit
Any data in memory is in binary form!
an int type of data occupies 4 bytes,32bit
For example:
Int number=12 ;
shown in memory as:
0000 0000 0000 0000 0000 0000 0000 1100
N bit binary Value range:
2 value range of bit bits: 0~3
3 value range of bit bits: 0~7
N range of values for bits: 2n-1
Test an integer with the binary output code:
Void putbinary (INTN)
{
Int bits = sizeof (n) *8-1;
while (bite>=0) {
Printf ("%d", n>>bit&1);
If (bits%4==0)
Printf ("");
}
Printf ("\ n");
}
Second, range of values for data types:
Char-----1 of bytes ---8bit--- range of values: -27~27-1
Int-------4 of bytes ---32bit--- range of values: -231-231-1
Float----4 of bytes ----32bit--- range of values: 3.4e-38~3.4e38| | -3.4e38~-3.4e-38
Double---8 of bytes ---64bit- range of values: 1.7e-308~1.7e308| | -1.7e308~1.7e-308 Three , type descriptor:
Int--------4 of bytes -----------%d
Short --------4 of bytes -----------%d
Long--------8 of bytes -----------%ld
Long Long----8 of bytes -------%lld
signed signed: Positive, 0 , Negative
unsigned unsigned: Contains 0 , Positive
signed with the unsigned The difference: signed The highest position should be regarded as the sign bit; unsigned The highest bit is not used as a sign bit.
Four, bit arithmetic
1. & bitwise and
For example:
9&5 ;
converting data into binary and arithmetic
2. | bitwise OR
For example:
9|5 ;
convert data into binary or arithmetic
3. ^ bitwise XOR: As long as two binary bits are not equal to 1 in place 0
For example:
9^5 ;
convert data into binary for XOR operation
n^n result is 0 ;
Any value that is 0 different or gets the original value
4. ~ bitwise to reverse
For example:
to ;
9 all the bits are reversed;
5.<< Move left
Move the bits of an integer all the way to the left N -bit high discard the low fill 0
6. >> Move Right
Move the bits of an integer all the way to the right N bits to keep the sign bit constant
Five, Char
// single quote ' ' can only enclose single-byte characters
//char c= ' male ' This is the wrong wording .
//char c = "A"; This is the wrong wording .
//char c = A; This is also the wrong wording.
Char can be used as an integer, its value range is: -128~127 ;
Escape characters:
\ n line Break ASCII the value is Ten
\ t Skip to Next Tab location ASCII the value is 9
\\ represents a backslash character ASCII the value is the
\ ' represents a single quote character ASCII the value is the
Converts the case of a letter
Uppercase Upper
lowercase Lowwer
Char Upper (char c)
{
If (c>= ' a ' &&c<= ' Z ')
return c-32;
ElseIf
return C;
}
This article is from the "I am the way of it Growth" blog, please be sure to keep this source http://jeason.blog.51cto.com/9704473/1594078
Memory Analysis in C language