🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Converting Ordinary String to Hex Representation

#8496
From: Owen Green
Date: Thu, 15 Mar 2001 14:00
21 lines
1550 bytes
> I need to convert a simple text string to the hex representation of that
> string.  That representation in of itself should be another string.  For
> instance in the string was "1 2" (The number 1, a space, and the number 2)
> I would want a HEX presentation of "312032".

There's almost certainally a better way of doing this, but for what it's
worth:

  public String toCharCodes(String inStr){
    byte[] bytes  = inStr.getBytes();
    StringBuffer byteBuffer = new StringBuffer();

    for(int i=0;i<bytes.length;i++){
      byteBuffer.append(Integer.toHexString((int)bytes[i]));
    }
    return byteBuffer.toString();
  }

hth,
Owen
Technical Details
Message-ID: <3ab0cb0d$1_1@dnews>
Path: arc1-ca.pugleaf.net!pubnews.netcom.net.uk!diablo.netcom.net.uk!netcom.net.uk!newsfeed.icl.net!europa.netcrusader.net!128.230.129.106!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!213.86.7.136
References: <3ab065d9$1_1@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,2d3641429c1fd31
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-03-17 07:55:10 PST
From: "Owen Green" <owen@norobots.unique.com>
Newsgroups: borland.public.jbuilder.java.language
References: <3ab065d9$1_1@dnews>
Subject: Re: Converting Ordinary String to Hex Representation 
Date: Thu, 15 Mar 2001 14:00:43 -0000
Lines: 23
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 213.86.7.136
Message-ID: <3ab0cb0d$1_1@dnews>
X-Trace: 15 Mar 2001 06:00:45 -0800, 213.86.7.136
Path: arc1-ca.pugleaf.net!pubnews.netcom.net.uk!diablo.netcom.net.uk!netcom.net.uk!newsfeed.icl.net!europa.netcrusader.net!128.230.129.106!news.maxwell.syr.edu!newsfeed.wirehub.nl!PeerFeed.KWeb.on.ca!dnews!213.86.7.136