- void test2(){
 
  
-     //提示用户输入
 
 -     printf("请输入一个整数:\n");
 
 -     
 
 -     //定义变量记录用户的输入
 
 -     int getResult = 0;
 
 -     int result = 0;
 
 -     int n = 0;
 
 -     
 
 -     //接收用户输入的值
 
 -     scanf("%d%*c%d",&getResult,&n);
 
 -     
 
 -     if (n > 0) {
 
 -         //右移
 
 -         for (int i = 0; i < 32; i++) {
 
 -             
 
 -             int result = getResult;
 
 -             
 
 -             if (i < n) {
 
 -                 
 
 -                 //取对应右移位置的数值
 
 -                 result = result >> (n - i -1) & 1;
 
 -                 
 
 -             }else{
 
 -                  //输出原来最高位的数值
 
 -                  result = (result >> (31 - i + 1)) & 1;
 
  
-             }
 
 -             //输出每个位上面的数字
 
 -             printf("%d",result);
 
 -         }
 
 -         printf("\n");
 
 -         
 
 -     }else if (n < 0){
 
 -          n *= -1;
 
 -     
 
 -         //左移
 
 -         for (int i = 0; i < 32; i++) {
 
 -             
 
 -             int result = getResult;
 
 -             
 
 -             if (i < n) {
 
 -                 
 
 -                 //取对应左移位置的数值
 
 -                 result = result >> (n - i -1) & 1;
 
 -                 
 
 -             }else{
 
 -                 //输出没被切掉的值
 
 -                 result = (result >> (31 - n)) & 1;
 
 -                 
 
 -             }
 
 -             //输出每个位上面的数字
 
 -             printf("%d",result);
 
 -         }
 
 -         printf("\n");
 
 -         
 
 -     }else{
 
 -         if (n == 0) {
 
 -            
 
 -             //不移动
 
 -             for (int i = 0; i < 32; i++) {
 
 -                 
 
 -                 result = getResult;
 
 -                 result = result >> (31 - i) & 1;
 
 -                 printf("%d",result);
 
 -                 
 
 -             }
 
 -             printf("\n");
 
 -         }
 
 -     }
 
 - }
 
  复制代码 |   
        
 
    
    
    
    
 
 
 |