I got these errors in my function that prints out a byte in 1’s and 0’s. I don’t get why it’s saying that there will be a loss of precision if a byte type in Java is 8 bits and I assigned exactly 8 bits to that byte type.
==============================================
dcllnx17> javac PrintSimilarity.java
./Neighbors.java:25: possible loss of precision
found : int
required: byte
byte ander = 0x80;
^
./Neighbors.java:30: possible loss of precision
found : int
required: byte
ander = 0x80 >>> bit;
^
2 errors
// Name: charToBin
// Input: a single byte
// Output: none
// Purpose: prints out the character input in binary
public static void charToBin(byte theByte)
{
// ander = 1000 0000
byte ander = 0x80;
// tests each bit of input by ANDing 1 with each bit
for(int bit = 0; bit < 8; bit++)
{
ander = 0x80 >>> bit;
if((ander & theByte) == ander)
System.out.print("1");
else
System.out.print("0");
}
}