Attn:Mark Space... My Ascii 2 Hex back 2 Ascii program.



I've completed a working program. It takes console input of an ascii
string, converts it to it's Hex value and then converts the Hex value
back to the Ascii string value.

import java.io.*;
import java.lang.*;
//Convert ASCII to HEX Then Convert BACK to string value
class Hex2Ascii2Hex
{
public static void main(String[] args) throws Exception
{
// system.in reader (the input from console)
InputStreamReader inputStream = new InputStreamReader(System.in);
// buffer the console reader
BufferedReader br = new BufferedReader(inputStream);
{
// output the question.
System.out.print("Enter STRING : ");
// read console intput one line (BR.readLine) and store as
String
String asciiString = (br.readLine());
// Covert to HEX
for(int i = 0; i<asciiString.length(); i++)
{
System.out.println();
int ch=(int)asciiString.charAt( i );
String hexVal="00"+Integer.toHexString( ch );
System.out.print(i + "HEX VALUE IS :"+hexVal); // String to Hex

//Convert back to Ascii(String) value
int intVal = Integer.parseInt(hexVal, 16);
char charVal = (char) intVal;
System.out.print("...ASCII(String) Value : "+charVal);
}
}
}
}

Do you, or anyone else, see room for improvement??

I plan on adding functionality to make all the input from a file and
all output to a file. I may need console output to give display of
steps.

Thanks.
.



Relevant Pages

  • Re: healp reading / writing binary strings.
    ... Robert Klemme wrote: ... > And how can I write the same type of string from say an ... to the ascii table as well? ... for hex, does the hex value I supply correspond to the ascii table as ...
    (comp.lang.ruby)
  • Re: Attn:Mark Space... My Ascii 2 Hex back 2 Ascii program.
    ... converts it to it's Hex value and then converts the Hex value ... back to the Ascii string value. ... // system.in reader (the input from console) ...
    (comp.lang.java.help)
  • Re: Attn:Mark Space... My Ascii 2 Hex back 2 Ascii program.
    ... // buffer the console reader ... BufferedReader br = new BufferedReader( ... Just making a point that all numbers are hex, decimal and binary and internal format doesn't really matter. ... public static void main(String[] args) throws Exception ...
    (comp.lang.java.help)
  • Re: Creating a unique number from a text string
    ... For example you could turn each character's ASCII ... code into a hex number: ... You can also look at something called Base-64, ... designed to turn any string into "easy" characters. ...
    (comp.databases.ms-access)
  • Re: How to construct a string with bunch of hex numbers?
    ... to construct a string with those hex numbers? ... No. I'd like to have a string like "xyzabc" and each ASCII char corresponds ... to a hex number. ...
    (microsoft.public.dotnet.languages.csharp)