@@ -103,45 +103,60 @@ public static String convertToString(Byte[] data, int base, boolean showAscii) {
103103 ConversionConstants convConst = getConstants (base );
104104
105105 // Convert each byte and put into string buffer
106- for (int i =0 ; i < data .length ; i ++) {
106+ for (int i = 0 ; i < data .length ; i ++)
107+ {
107108 int value = data [i ].byteValue ();
108109 String s = null ;
109-
110+
110111 // if user wants to see ASCII chars as characters,
111112 // see if this is one that should be displayed that way
112- if (showAscii ) {
113- if (printable .indexOf ((char )value ) > -1 ) {
114- s = Character .valueOf ((char )value ) +
115- " " .substring (10 -(convConst .width - 1 ));
113+ if (showAscii )
114+ {
115+ if (printable .indexOf ((char ) value ) > -1 )
116+ {
117+ s = Character .valueOf ((char ) value ) + " " .substring (10 - (convConst .width - 1 ));
116118 }
117119 }
118-
120+
119121 // if use is not looking for ASCII chars, or if this one is one that
120122 // is not printable, then convert it into numeric form
121- if (s == null ) {
122- switch (base ) {
123- case DECIMAL :
123+ if (s == null )
124+ {
125+ switch (base )
126+ {
127+ case DECIMAL :
124128 // convert signed to unsigned
125- if (value < 0 )
129+ if (value < 0 )
130+ {
126131 value = 256 + value ;
127- s = Integer .toString (value ); break ;
128- case OCTAL : s = Integer .toOctalString (value ); break ;
129- case BINARY : s = Integer .toBinaryString (value ); break ;
130- case HEX : // fall through to default
132+ }
133+ s = Integer .toString (value );
134+ break ;
135+ case OCTAL :
136+ s = Integer .toOctalString (value );
137+ break ;
138+ case BINARY :
139+ s = Integer .toBinaryString (value );
140+ break ;
141+ case HEX : // fall through to default
131142 default :
132143 s = Integer .toHexString (value );
133144 }
134145 // some formats (e.g. hex & octal) extend a negative number to multiple places
135146 // (e.g. FC becomes FFFC), so chop off extra stuff in front
136- if (s .length () > convConst .width )
147+ if (s .length () > convConst .width )
148+ {
137149 s = s .substring (s .length () - convConst .width );
138-
150+ }
151+
139152 // front pad with zeros and add to output
140- if (s .length () < convConst .width )
141- buf .append ("00000000" .substring (8 -(convConst .width - s .length ())));
153+ if (s .length () < convConst .width )
154+ {
155+ buf .append ("00000000" .substring (8 - (convConst .width - s .length ())));
156+ }
142157 }
143158 buf .append (s );
144- buf .append (" " ); // always add spaces at end for consistancy
159+ buf .append (" " ); // always add spaces at end for consistancy
145160 }
146161 return buf .toString ();
147162 }
0 commit comments