How to find if two numbers are consecutive numbers in gray code sequence

后端 未结 9 1113
醉梦人生
醉梦人生 2021-02-04 18:44

I am trying to come up with a solution to the problem that given two numbers, find if they are the consecutive numbers in the gray code sequence i.e., if they are gray code neig

9条回答
  •  无人共我
    2021-02-04 19:13

    public int checkConsecutive2(int b1, int b2){
        int x =  (b1 ^ b2);
    
        if((x & (x - 1)) !=0){
          return 0;
        }else{
          return 1;
        }
    
    }
    

提交回复
热议问题