# \[Java\] Loss of Precision

**URL:** <https://forum.kirupa.com/t/java-loss-of-precision/238849>\
**Category:** programming\
**Created:** [September 16, 2007, 5:52am UTC](https://forum.kirupa.com/t/java-loss-of-precision/238849 "2007-09-16T05:52:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [September 16, 2007, 5:52am UTC](https://forum.kirupa.com/t/java-loss-of-precision/238849/1 "2007-09-16T05:52:57Z")

</div>

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

```auto

   // 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");
      }
   }   

```
