Hello,
I am trying to convert a high number (e.g. 123456789) into a character and then reconvert that character into the first number in another file.
To do this, I am using CHAR and ICHAR functions.
Using:
[tt] WRITE(*,*) ICHAR(CHAR(123456789,4),4) [/tt]
I get the number 123456789
However, when I try to separate the steps
[tt]
CHARACTER*1 TMPC1
INTEGER*4 TMPI1
INTEGER*4 NUMBER
NUMBER = 123456789
TMPC1 = CHAR (NUMBER,4)
TMPI1 = ICHAR (TMPC1,4)
WRITE(*,*) TMPI1 [/tt]
The ICHAR function only allows a character input of length 1 !!
I get the number 21. At first this was a bit confusing. It became clear when I used this program to convert the numbers 0, 1, 2, 3, ..., 300
The conversion was flawless until number 254, and then reseted:
253 > 253
254 > 254
255 > 255
256 > 0
257 > 1
This is due to the limited number of ASCII characters, which is 255.
Any thoughts on how to convert a number larger than 255, and retrieve the same number?
Many thanks!
I am trying to convert a high number (e.g. 123456789) into a character and then reconvert that character into the first number in another file.
To do this, I am using CHAR and ICHAR functions.
Using:
[tt] WRITE(*,*) ICHAR(CHAR(123456789,4),4) [/tt]
I get the number 123456789
However, when I try to separate the steps
[tt]
CHARACTER*1 TMPC1
INTEGER*4 TMPI1
INTEGER*4 NUMBER
NUMBER = 123456789
TMPC1 = CHAR (NUMBER,4)
TMPI1 = ICHAR (TMPC1,4)
WRITE(*,*) TMPI1 [/tt]
The ICHAR function only allows a character input of length 1 !!
I get the number 21. At first this was a bit confusing. It became clear when I used this program to convert the numbers 0, 1, 2, 3, ..., 300
The conversion was flawless until number 254, and then reseted:
253 > 253
254 > 254
255 > 255
256 > 0
257 > 1
This is due to the limited number of ASCII characters, which is 255.
Any thoughts on how to convert a number larger than 255, and retrieve the same number?
Many thanks!