Trimming trailing zeros in a byte
I present you with a pair of methods. The main method executes the convert method (which I learnt thanks to a member, unfortunately I forgotten his name but I thank him again for his help). The convert method basically takes an integer and delivers its bitwise representation to be stored in a byte.
public static void main(String args)
public static void convert()
int b = 0;
for (int m = 1; m != 0; m <<= 1)
b = 5; //b is the current int
int bit = ((b & m) != 0)? 1:0;
byte c = (byte)bit;
The output: 101000000000000000......
How do I remove the trailing zeros?
EDIT: The output is obviously reversed... in fact 5 = ....000000101
Thank you in advance.