i wrote simple java code to convert from decimal to 8-bit binary: sorry for this stupid question
1 int dec=1;
2 String result="";
3 String reverse = "";
4 while(dec!=0)
5 {
6 result+=dec%2;
7 dec=dec/2;
8 }
9 //8-Bit Binary
10 System.out.println("dec length is :"+result.length());
// int j=8-result.length(); // for(int i=0;i
11 for(int i=0;i<(8-result.length());i++)
12 {
13 result+=0;
14 System.out.println("*");
15 }
16 System.out.println("8-Bit before reverse:"+result);
17 for(int i = result.length() - 1; i >= 0; i--)
18 {
19 reverse = reverse + result.charAt(i);
20 }
21 System.out.println("8-bit representation:"+reverse);
the result was : dec length is :1 * * * * 8-Bit before reverse:10000 8-bit representation:00001
but when i remove line 13 (result+=0;) the compiler print 7 asterisk(*), what is the reason for that? length of result will update every time