"Efficient Algorithms Notes" learning

The basic expression of conversion

#include<bits/stdc++.h>
const int inf=0x7fffffff;
using namespace std;
int main() 
{  
     int x,y;
	 x=rand()%10+1;
	 y=rand()%10+1; 
	 cout<<" x、y的值:"<<x<<" "<<y<<endl;
	 cout<<" x的相反数为:"; 
	 cout<<(-x)<<" --> "<<~x+1<<endl;    // -x=~(x-1)=~x+1
	 cout<<" x+y的值为:";
	 cout<<(x+y)<<" --> "<<(x|y)+(x&y)<<endl;   // x+y=(x|y)+(x&y)=x-~y-1
	 cout<<" x+1的值为:"; 
	  cout<<(x+1)<<" --> "<<-~x<<endl;     //x+1 = -~x
	  cout<<" x-y的值为: ";
	  cout<<(x-y)<<" --> "<<x+~y+1<<endl;   //x-y= x+~y+1
	  cout<<" x&y的值:";
	  cout<<(x&y)<<" --> "<<(~x|y)+x+1<<endl;   // x&y=(~x|y)+x+1
	  cout<<" x|y的值:"; 
	  cout<<(x|y)<<" --> "<<(x&~y)+y<<endl;    //x|y==(x&~y)+y
	  cout<<" x的绝对值为:";
	  cout<<((x>0)?x:(-x))<<" --> "<<((x>>30|1)*x)<<endl; //x的平均值为 (x>>30|1)*x 
	  cout<<" 判断x是正/负数/0 ";  
	  cout<<(x>0?1:(x==0?0:-1))<<" --> "<<((x>=0)-(x<=0))<<endl; //  判断x是正/负数/0  == (x>=0)-(x<=0)
	  return 0;	  
 }   

Released nine original articles · won praise 0 · Views 102

Guess you like

Origin blog.csdn.net/weixin_44586132/article/details/103414602