java - println error when printing bytes -


i have wrote simple program below output hello in arabic language :"سلام" it's output on console not correct:

import static java.lang.integer.tobinarystring;  import java.util.arrays;   public class testofprintln {     public static void main(string []strings){         string test="salam";         string test2="سلام";//unicode , arabic         byte []strbytes=test.getbytes();         int i=1;         for(byte bb:strbytes)             system.out.println(i++  + "    -> " + bb);         byte []strbytes2=test2.getbytes();         i=1;         for(byte bb2:strbytes2){             system.out.println(i++  + "    ->   " + bb2);         }     }  } 

and output:

1    -> 115 2    -> 97 3    -> 108 4    -> 97 5    -> 109 1    -> -40 2    -> -77 3    -> -39 4    -> -124 5    -> -40 6    -> -89 7    -> -39 8    -> -123 

why there "-" character before bytes? example: -123 tnx.

in java byte signed integer values ranging -128 127. if want unsigned values, cast int (happens implicitly when anding) , and 255.

system.out.println(i++  + "    -> " + (bb & 0xff)); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -