Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting char to hex

2 views
Skip to first unread message

Laurent Demailly

unread,
Oct 13, 1995, 3:00:00 AM10/13/95
to
proc char2hex {c} {
scan $c %c ascii;
format %x $ascii
}
puts [char2hex "a"]

In article <45luqe$f...@aix11.hrz.uni-oldenburg.de>,
Edwin Litterst <e...@fiz-karlsruhe.de> wrote:
>I tried (invain) to "convert" a character to a hexadecimal representation.
>What I want is a way to create e.g. the string 61 (hex. value) from e.g. the character a.
>How is this done? I have tried format but %x doesn't seem to do that.
format works on numbers, you need to use scan first to go from
char to ascii code...

regards
dl
--
Laurent Demailly * http://hplyot.obspm.fr/~dl/ * Linux|PGP|Gnu|Tcl|... Freedom
Prime#1: cent cinq mille cent cinq milliards cent cinq mille cent soixante sept

John Rickard

unread,
Oct 13, 1995, 3:00:00 AM10/13/95
to
Edwin Litterst (e...@fiz-karlsruhe.de) wrote:

: I tried (invain) to "convert" a character to a hexadecimal
: representation. What I want is a way to create e.g. the string 61
: (hex. value) from e.g. the character a.

I think you have to go by way of the decimal representation:

% info tclversion
7.3
% scan a %c code ; format %x $code
61
%

--
John Rickard

Edwin Litterst

unread,
Oct 13, 1995, 3:00:00 AM10/13/95
to
Hello,

I tried (invain) to "convert" a character to a hexadecimal representation.
What I want is a way to create e.g. the string 61 (hex. value) from e.g. the character a.

How is this done? I have tried format but %x doesn't seem to do that.

Thanks in advance,
Eddi

0 new messages