title: How to convert string of 0s and 1s to unsigned Byte?
body: <p>Here, I have an array containing 0,1,-1's. I am replacing all -1's to 0's and then creating a String of 0's and 1's. Later, converting the string to Byte but by default, Byte.parseByte() converts the string to signed Byte. Please suggest to me a solution to convert it to an unsigned Byte.</p>
  <pre class="lang-java prettyprint-override"><code>public class Test{
  
       public static void main(String []args){
          int[][] intArray = new int[][]{ 
              {-1,0,0,-1,0,1,1,0},
              {1,1,0,-1,0,0,-1,0},
              {-1,0,1,1,0,-1,1,0},
              {1,-1,-1,0,0,1,-1,0}
          }; 
          
          
          for(int j=0; j&lt;intArray.length;j++){
              String BitString = &quot;&quot;;
              for(int i=0; i&lt;8;i++ ){
                  if (intArray[j][i] == -1){
                      BitString = BitString + &quot;0&quot;;
                  }
                  else{
                      BitString = BitString + intArray[j][i];
                  }
              }
              System.out.println(BitString);
              
              try{
                  Byte b = Byte.parseByte(BitString,2);
                  System.out.println(b);
                  System.out.println(b.getClass().getName());
              }
              catch(Exception e){
                  System.out.println(e.toString());
              }
              System.out.println(&quot;\n&quot;);
          } 
       }
  }
  </code></pre>
  <p>Sample Output:</p>
  <pre class="lang-java prettyprint-override"><code>00000110
  6
  java.lang.Byte
  
  
  11000000
  java.lang.NumberFormatException: Value out of range. Value:&quot;11000000&quot; Radix:2
  
  
  00110010
  50
  java.lang.Byte
  
  
  10000100
  java.lang.NumberFormatException: Value out of range. Value:&quot;10000100&quot; Radix:2
  </code></pre>