+ 2

convert to from decimal to int to hexadecimal with 8 bits

Hi guys I made a programm to convert decimal to int and to hexadecimal, the problem is that i can't get a function that shows me the 8 bits properly (ceros on the left). That's why I used a trick, which ain't so fancy. If somebody has the solution please leave a comment https://code.sololearn.com/cNVZE3DtwrHu

23rd Nov 2017, 9:56 PM
Vas
Vas - avatar
2 Answers
+ 2
This should give you the output you want: for (int counter = 1; counter < 128; counter++) { String s = "0000000"+Integer.toBinaryString(counter); System.out.println(s.substring(s.length()-8)); }
24th Nov 2017, 12:32 AM
John Wells
John Wells - avatar
+ 2
Thanks I will try it out
24th Nov 2017, 8:10 AM
Vas
Vas - avatar