🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16029

Re: Hexadecimal string to string

#16029
From: Tor Iver Wilhelmsen
Date: Thu, 08 Apr 1999 00:00
24 lines
1399 bytes
"Omer Azhar Qureshi" <oaq@systemeltd.com.pk> writes:

> Tor,
> i dont think that u understood the problem at hand properly,
> the Integer.parseInt (HexString, 16) method converts a hexadecimal string
> into its decimal equvalant (an int) while the problem requires that a
> Hexadecimal String be converted into its ASCII equavalant (also a
> String)....

Okay: You want to parse two and two hex digits and turn them into an
8-bit character?

int l = theString.length();
if ((l % 2) != 0)
  throw new NumberFormatException("Unbalanced hex string");
StringBuffer build = new StringBuffer();
for (int i = 0; i < l; i += 2) {
  char sixteensDigit = string.charAt(i);
  char onesDigit = string.charAt(i+1);
  char ascii = (char) (Character.digit(onesDigit, 16)
    + 16 * Character.digit(sixteensDigit, 16));
  build.append(ascii);
}
return build.toString();
Technical Details
Message-ID: <uhfqrbivk.fsf@sds.no>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7doad4$7fo14@forums.borland.com> <uaewmgk1b.fsf@sds.no> <7ehpfh$1i54@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,b25984f20866b948
X-Google-Attributes: gidf74b3,public
From: Tor Iver Wilhelmsen <tor.wilhelmsen@sds.no>
Subject: Re: Hexadecimal string to string
Date: 1999/04/08
Message-ID: <uhfqrbivk.fsf@sds.no>
X-Deja-AN: 463964460
Sender: towi@SDSA1761
References: <7doad4$7fo14@forums.borland.com> <uaewmgk1b.fsf@sds.no> <7ehpfh$1i54@forums.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language