ASCII to integer transformation question? 
Author Message
 ASCII to integer transformation question?

Ergun Ergin US/ENI 60/2/152 #47035 wrote in article

Quote:
>I would like to change the represantation of a character value from ASCII
>to integer (infact ASCII to string in Tcl).
>For example for the character 'A' it should yield to "65" and for the
character
>'B' it should yield to "66" and so on.
>I use tcl8.0 and `format' command does not support this.
>Currently I use an internal array in the following form:
>set {characterMap(A)} 65
>set {characterMap(B)} 66
>set {characterMap(C)} 67
>...

>but there should be easier way to do this.

Try:

    scan A %c int_value

you might also want to look at the new binary command, particularly the scan
option.

****************************************************************************
* Gerald W. Lester                       | Voice:  +1 (504)-889-2784       *
* Computerized Processes Unlimited, Inc. | FAX:    +1 (504)-889-2799       *

* Metairie, LA 70001                     | Web:     http://www.*-*-*.com/      *
****************************************************************************



Mon, 20 Mar 2000 03:00:00 GMT  
 ASCII to integer transformation question?


Quote:

> I would like to change the represantation of a character value from ASCII
> to integer (infact ASCII to string in Tcl).
> For example for the character 'A' it should yield to "65" and for the character
> 'B' it should yield to "66" and so on.
> I use tcl8.0 and `format' command does not support this.
> Currently I use an internal array in the following form:
> set {characterMap(A)} 65
> set {characterMap(B)} 66
> set {characterMap(C)} 67
> ...

> but there should be easier way to do this.

Use, for example :
  binary scan A c aValue
  binary scan B c bValue
  ...

after, the aValue will hold 65, bValue 66 ...
  IF you think it will be easier to write, easier to read the source,
quicker, etc.

Also, look into manual pages regarding 'binary'.

______________________________________________________________________



Mon, 20 Mar 2000 03:00:00 GMT  
 ASCII to integer transformation question?

I would like to change the represantation of a character value from ASCII
to integer (infact ASCII to string in Tcl).
For example for the character 'A' it should yield to "65" and for the character
'B' it should yield to "66" and so on.
I use tcl8.0 and `format' command does not support this.
Currently I use an internal array in the following form:
set {characterMap(A)} 65
set {characterMap(B)} 66
set {characterMap(C)} 67
...

but there should be easier way to do this.

Thanks for any help in advance.

Ergun Ergin Gouveia

Alcatel Telecom




Mon, 20 Mar 2000 03:00:00 GMT  
 ASCII to integer transformation question?

Quote:
> > I want to change a character value from ASCII to integer
> > I use tcl8.0 and `format' command does not support this.
> > Currently I use an internal array:
> > set {characterMap(A)} 65
> > set {characterMap(B)} 66
> > set {characterMap(C)} 67
> > ...
> > but there should be easier way to do this.
> Use, for example :
>   binary scan A c aValue
>   binary scan B c bValue
>   ...

in all the TCLs you could write these as
        for {set i 1} {$i<256} {incr i} { set [format characterMap(%c) $i] $i }
and
        scan A %c aValue
i use the array myself; it's a little faster in some uses.

--
Hume dot Smith at Dess dot Tallships dot iStar dot CA



Mon, 20 Mar 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Convert ASCII numerals to Integer numbers

2. INTEGER TO ASCII CONVERSION CODE

3. INTEGER TO ASCII CONVERSION CODE

4. Converting integers to ASCII

5. How to transfer 10 bit binary integer to ASCII code

6. Convert 10 bit integer to ascii code--how?

7. ASCII-INTEGER Converting with G77

8. ascii to integer?

9. integer to ascii

10. Reading single ASCII as integer value (how ?)

11. A Question on Matrix Transformation Using J.

12. A question on semantics and program transformation

 

 
Powered by phpBB® Forum Software