Name: boT120536 Date: 12/27/2000
Origonal Synopsis
Not properly converting from int to binary/hexadecimal format
?java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
Here is the source Code , for the Data Type Conversion Problem.
package mpt.GeneralFunctions;
import java.io.*;
public class ConvertingTypes {
private final String cdVERSION = "01.00.000";
public ConvertingTypes() {
}
public String getVersion() {
return cdVERSION;
}
public String int2hexa(int intVAL , int lenVAL) throws
IllegalArgumentException , IOException {
int workV = intVAL;
int restoV = 0;
final int bufLEN = lenVAL;
StringWriter strBUFF = new StringWriter();
if ( lenVAL > 8 ) {
throw new IllegalArgumentException ("Tamanho maximo deve ser de
oito (8) Bytes.");
}
// Verifica se o valor eh menor que 256. Se for faz a conversao
imediatamente e deixa a rotina
// Apesar de nao ser elegante , eh uma solucao mais eficiente e
simples , evitando
// controles adicionais no Loop de Conversao
boolean doIT = true;
boolean doShift = false;
while (doIT) {
restoV = workV % 16;
workV = workV / 16;
if ( doShift ) {
restoV = restoV * 16;
}
doShift = !doShift;
strBUFF.write(restoV);
if ( workV == 0 ) {
doIT = false;
}
System.out.println("R=" + restoV + " W="+ workV);
}
return strBUFF.toString();
}
}
Lets suppose that intVal = 144 // 144 = 0x90
or intVal = 141 // 141 = 0x8D.
If I run the class and uses the standard output direct to a file the output is
OK. Expept for the string returned in return Statement , wich returns 63 , wich
is 0x3F.
(Review ID: 113884)
======================================================================
- duplicates
-
JDK-4276747 (cs)   (char \00a0) prints as ?
-
- Closed
-