////main.m//Lesssonscale////Copyright (c) 2015 Chi Hai Tao. All rights reserved.//#import<Foundation/Foundation.h>intMainintargcConst Char*argv[]) {Take 10 as an example, the notation of the different binary decimal:TenBinary : 0B10; Octal:01016 binary: 1x10; intA =0b100; printf ("%0x\n", a); How to output the binary number:%d------decimal%o------octal%0x------Hexadecimal bitwise operators: bitwise&, bitwise OR |, bitwise NON ~, bitwise XOR, Shift left <<, right Shift >>bitwise-and&: The same 1 is 1, otherwise 0, often used to a certain one Qing 0intA =5&7; 5--0101 7--0111=0101=5printf ("A =%d\n", a); Bitwise OR|: The same 0 is 0, otherwise 1. Often used to keep a certain bit. intA =5|7; 5--0101 7--0111=0111printf ("A =%d\n", a); Bitwise XOR or^The same is 0, the difference is 1. intA =5^7; 5--0101 7--0111=0010=2printf ("A =%d\n", a); Bitwise non-~; Charb = ~4;//4--0000 0100, ~4=1111 1011-1->1111 1010->1000 0101 =-5printf"B =%d\n", B); If it is a number with a signed bit, this highest bit represents the sign bit,1Represents a negative number,0represents positive data in memory, is stored in the form of complement, the positive number of the complement is positive, the complement of negative is the absolute value of the inverse plus 1. Range of values for data types:
Depending on the value range of char and the number of bits of the range of unsigned char, such as char and unsigned char are 8 bits, the highest bit of char is the sign bit, and 1 is negative, so -2^7-1~~+2^7-1 is -128~+1 while unsigned char is 2^8-1=256
namely 0~255
Unsigned :Char 0-----255(2 of the 8-time minus 1) Short 0-----2 of 16-1; int 0-----2 of 32-1; there are symbols:Char-2 of the 7-time---2 of the 7 parties-1 Short-2 of the 15-time---2 of the 15 parties-1 int-2 of the 31-time---2 of the 31 parties-1Move left<<unsignedCharD =1; printf ("The result after the left shift%d\n", D <<4 ); Move Right>>unsignedCharE =255; printf ("The result after the right shift%d\n", e >>1); //100 high four-bit, low four-bit interchange unsignedCharNumber =0b01100100;//1. Move number to the left 4 bits firstUnsignedCharleft = number <<4; //2. Move number to the right 4 bitsUnsignedCharright = number >>4; //3. Bitwise OR unsignedCharresult = left |Right ; printf ("result =%d\n", result); Will be10010010parity and even bit interchange unsignedCharnum =0b10010010;//The 0 operation uses the bitwise &, and the reserved digits are 1, and the bits of 0 are 0 .//1. Turn odd digits into even digits and move left one unsignedCharLife = num <<1; //2. Reserved even digits, odd digit 0 unsignedCharClearji = Life &0b10101010;//3. Turn the even digits to odd digits and move right 1 bits unsignedCharrightnew = num >>1; //4. Reserved odd digits, even number of bits clear 0 unsignedCharClearou = rightnew &0b01010101;//5. Bitwise OR | unsignedCharResultnew = Clearji |Clearou; printf ("resultnew =%d \ n", resultnew); Stack memory allocation principle: from high to the bottom of the allocation, have low to high access. intA =Ten; printf ("%p\n",&a); intb =Ten; printf ("%p\n",&b); //The array name represents the first address of the array, which is the address of the first element of the array, which is a constant address inta[4] = {9,5,2,7}; printf ("%p\n", &a[0]); printf ("%p\n", &a[1]); printf ("%p\n", &a[2]); printf ("%p\n", &a[3]); printf ("%p\n", a); A=1010b=1100a=0110b=1010 //swap two variables intA=Ten, b= A;//a=1010^b=1100;A=a^b;//a=0110//find the different bits in A and BB=a^b;//b=1010//Original B and AB are different or a =1010A=a^b;//a=1100// printf"A =%d\nb =%d", A, b); return 0; }
iOS in-process