Converting decimal to binary in Java

前端 未结 9 2315
时光取名叫无心
时光取名叫无心 2020-12-03 15:18

I\'m trying to write a code that converts a number to binary, and this is what I wrote. It gives me couple of errors in Eclipse, which I don\'t understand. What\'s wrong wit

9条回答
  •  天涯浪人
    2020-12-03 16:16

    Here is a small bittesting code I made for Android.

    int myres = bitTest(7, 128);

    public int bitTest(int bit,int value)
     {
        int res = 0;
        int i = 0;
        while (i <= bit) {
            res = (value & 1);
            value = value >> 1;
            i++;
        }
        return res;
     }
    

    Best Regards Mikael Andersson

提交回复
热议问题