FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   hex to string conversion...
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: hex to string conversion...  (Read 601 times)
diriccio


hex to string conversion...
« on: Oct 25th, 2004, 10:24pm »

hi!
 
is there a way to get the following to work in p69?
 
 
 
import java.util.*;
 
public class hex2string
{
 public static void main(String[] a)
 {
  String encoding = "iso-8859-1"; // or "utf-8", etc
 
  String hex = "31 32 33 41 42 43";
 
 
  StringTokenizer st = new StringTokenizer(hex, " \n\r");
 
  int count = st.countTokens();
  byte[] buf = new byte[count];
 
  int i = 0;
  while (st.hasMoreTokens()) {
   buf[i] = Byte.valueOf(st.nextToken(), 16).byteValue();
   i++;
  }
 
  try {
   String text = new String(buf, encoding);
   System.out.println(text);
  }
  catch (Exception e) {
   e.printStackTrace();
  }
 
 
 }
}
 
 
 
thanks a lot!
 
diriccio


Re: hex to string conversion...
« Reply #1 on: Nov 1st, 2004, 12:41pm »

... it is basically just to transform a hexadecimal string like "223E 3C69 6D67 2062" into readable characters.
is there any predefined method to do this in processing??
 
much appreciated!
 
fry


WWW
Re: hex to string conversion...
« Reply #2 on: Nov 1st, 2004, 3:39pm »

on Oct 25th, 2004, 10:24pm, diriccio wrote:
is there a way to get the following to work ...

 
yeah, that code is ok, but take out the "import" line, and the "public class" line, and instead of it being a main(), put it inside a function that's used from an applet. processing only deals with applets, and doesn't know how to use the main() method.
 
fry


WWW
Re: hex to string conversion...
« Reply #3 on: Nov 1st, 2004, 3:40pm »

on Nov 1st, 2004, 12:41pm, diriccio wrote:
... it is basically just to transform a hexadecimal string like "223E 3C69 6D67 2062" into readable characters.
is there any predefined method to do this in processing?
 
much appreciated!

you can use a method like what the other poster wrote, but there isn't a built-in way in the currently available releases. in revision 70 and higher there are functions called hex() and unhex() which take care of this.
 
diriccio


Re: hex to string conversion...
« Reply #4 on: Nov 1st, 2004, 9:15pm »

thanks fry! i'll give it a go!
 
Pages: 1 

« Previous topic | Next topic »