Java integer to byte -


i have following code:

byte[] somearray; int a,b; . . . a=123; (result coming calculations, 0>=a<256) b=91; (result coming calculations, 0>=b<256) 

now want this

somearray[0]=a; somearray[6]=b; 

however tried convert in byte failed (getting possible error messages think). tried various snippets referring integer byte conversion.

so idea?

update java.lang.numberformatexception: invalid int: "z" when try bytearray[0]=integer.valueof(string.valueof(bani.substring(2, 3)), 16).bytevalue();

integer -> byte conversion result in compilation error because might result in precision loss. documentation.

however, can explicit cast:

somearray[0]=(byte)a; 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -