Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-03-2004, 05:42 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
convert a String to hex

is there an easy way to convert a string to hex? a class that will already do this? or do i need to make a byte array and do it that way?
__________________
Mike
sde is offline   Reply With Quote
Old 06-03-2004, 07:15 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,139
Belisarius is on a distinguished road
Do you mean a String as in the whole unicode set (Java doesn't use ASCII), or a String as in "14"?

What I would do is grab the char array (char can be cast as int), then call Integer.toHexString() on each of the characters, shoving them into a StringBuffer.

So:

Code:
char[] chars = foo.toCharArray();
StringBuffer output = new StringBuffer();
for(int i = 0; i < chars.length; i++){
  output.append(Integer.toHexString((int)chars[i]));
}
__________________
GitS
Belisarius is offline   Reply With Quote
Old 06-03-2004, 07:35 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,444
sde is on a distinguished road
I think that is what I wanted. I need to send strings through a medium which only supports hex.

I'm going to give this a whirl.

Thanks
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
From C to Java HighterDK Java 11 07-13-2004 07:15 PM
convert a string to a int , and back sde Standard C, C++ 3 03-02-2003 12:45 AM


All times are GMT -8. The time now is 05:31 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting