[Java] Loss of Precision
==============================================
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");
}
}
ander = (byte)(0x80 >>> bit);
byte ander = (byte) 0x80;The same thing happens on this line:
ander = 0x80 >>> bit;You're performing a bitshift on 0x80 (an integer) which results in another integer which you are then again assigning to a byte. So here, as eirche pointed out before, you have to cast it to a byte as well.
byte ander = 0x80;
#If you have any other info about this subject , Please add it free.# |

