Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How I convert Array of different ASCII Values into an Integer ?

Status
Not open for further replies.

RAJESHPARMAR

Programmer
Feb 17, 2013
4
0
0
Hi, I have 1 DAT File in which numeric data is stored in unknown format. When I converted each Character of unknown format in Ascii Value, it gives me following ASCII Value but in Application, this data is displayed as following Decimal Interger Number.

Ascii Value Decimal Value
----------- -------------
127,30,32,32 7807 }
63,31,32,32 7999 } for Integers
96,31,32,32 8032 }

Please help in defining the logic of converting this Ascii Values into Decimal Integer Value.

Thanks in Advance.
 
I'd suggest that, in each of your byte sequences:
[ul]
[li]The first two bytes are an Intel (Little-Endian) short (16-bit) integers.[/li]
[li]The second two bytes (both ASCII 32, or hexadecimal 20) are space characters.[/li]
[/ul]

i.e.
[ul]
[li]decimal 127 30 = hex L.E. 7f 1e = hex B.E. 1e7f = 7807[/li]
[li]decimal 63 31 = hex L.E. 3f 1f = hex B.E. 1f3f = 7999[/li]
[li]decimal 96 31 = hex L.E. 60 1f = hex B.E. 1f60 = 8032[/li]
[/ul]
 
Thanks for your reply ..

I have attached sample data file which contains the actual data in some unknown format and I have also converted this data in Ascii values.

Since the Actual Data contains different Data types like Integer, Float and Date, Please explain the steps of how this Ascii Values will be converted into Integer, Float Numbers and Date Format.

Also, Please let me know the language/Software in which this data of Unknown format is captured in the file.

Please go thru the attached Text File and waiting for your revert.

Thanks in advance .

Rajesh Parmar

 
Hi,

Pls ignore this reply if you have recieved the attached file in my earlier reply correctly. Also ignore "|" & "||" character as I have used this character as Seperator for better understanding.

a) Date Date Type ( like 16/02/2013) in unknown format :
_________________________________________________________

Date Ascii Values
<------------------------------------------->
|| üíÉÌB|, 32, 32,252, 2,237,201,204, 66||
|| X)òÉÌB|, 32, 32, 88, 41,242,201,204, 66||
|| ´O÷ÉÌB|, 32, 32,180, 79,247,201,204, 66||
|| ââùÉÌB|, 32, 32,226,226,249,201,204, 66||
|| vüÉÌB|, 32, 32, 16,118,252,201,204, 66||
|| lœÊÌB|, 32, 32,108,156, 1,202,204, 66||
|| ®¢Ê |, 32, 32,174,162, 19,202, 0, 0||


Note : Column Heading "Date" represent the date as actual data in file
and Column "Ascii Values" represent its corresponding Ascii Value
each Charaterwise.


b) Numeric Data Type : ( Integer and Float (Including Decimal Value like 123.515 ) ) in unknown format :

Int Ascii Values |
<------------------- >
| |, 1, 32, 32, 32|
| |, 1, 1, 32, 32|
|  |, 32, 1, 1, 32|
| |, 32, 32, 1, 1|
|B |, 66, 32, 32, 1|
|^@ |, 94, 64, 32, 32|
|¦? |, 1,166, 63, 32|
|? |, 63, 1, 32, 32|
|@ |, 8, 64, 1, 32|
| @|, 32, 8, 64, 1|
|$@ |, 36, 64, 1, 32|



Float Ascii Values
<----------------------------------------->
|ü©ñÒMbP?|,252,169,241,210, 77, 98, 80, 63|
|ü©ñÒMbP|, 1,252,169,241,210, 77, 98, 80|
| ü©ñÒMb|, 32, 1,252,169,241,210, 77, 98|
| ü©ñÒM|, 32, 32, 1,252,169,241,210, 77|
| ü©ñÒ|, 32, 32, 32, 1,252,169,241,210|
| ü©ñ|, 32, 32, 32, 32, 1,252,169,241|
| Ûù|, 32, 32, 32, 32, 32, 1,219,249|
| @|, 32, 32, 32, 32, 32, 32, 8, 64|
| &|, 1, 32, 32, 32, 32, 32, 32, 38|
|? |, 63, 1, 32, 32, 32, 32, 32, 32|
|P? |, 80, 63, 1, 32, 32, 32, 32, 32|
|bP? |, 98, 80, 63, 1, 32, 32, 32, 32|
|MbP? |, 77, 98, 80, 63, 1, 32, 32, 32|
|j¼t“? |,106,188,116,147, 63, 1, 32, 32|

Note : Column Heading "INT" and "Float" represent the actual data in file and Column "Ascii Values" represent its corresponding Ascii Value each Charaterwise.

Regards and Thanks in Advance.

Rajesh Parmar



 
Can't extract your file, and your "explanation" does not provide any suggested interpreted values (as per your initial question), so can only guess at formats:

[ul]
[li]For dates and times, perhaps held as seconds, or ticks (100 nanoseconds) since a base date (e.g. 01 January year 0000, or (on some systems 1970!); look up "DateTime" structures.[/li]
[li]No idea about your 'numeric' data; perhaps binary coded decimal, or fixed-point values?[/li]
[li]For floating point values, probably held in IEEE floating point format.[/li]
[/ul]
 
Hi,

Thanks for your revert.

Please find below with interpreted values.

a) Date Format :
-----------------

15/02/2007| üíÉÌB-|, 32, 32,252, 2,237,201,204, 66||
16/02/2007| *–ïÉÌB-|, 32, 32, 42,150,239,201,204, 66||
17/02/2007| X)òÉÌB-|, 32, 32, 88, 41,242,201,204, 66||
19/02/2007| ´O÷ÉÌB-|, 32, 32,180, 79,247,201,204, 66||
20/02/2007| ââùÉÌB-|, 32, 32,226,226,249,201,204, 66||
21/02/2007| vüÉÌB-|, 32, 32, 16,118,252,201,204, 66||
22/02/2007| ÿÉ -|, 32, 32, 32, 32,255,201, 0, 0||

b) Floating Point Numbers :
---------------------------

-ü©ñÒMbP?-|,252,169,241,210, 77, 98, 80, 63|| 0.001
-ü©ñÒMbP-|, 1,252,169,241,210, 77, 98, 80|| 0.001
- ü©ñÒMb-|, 32, 1,252,169,241,210, 77, 98|| 0.001
- ü©ñÒM-|, 32, 32, 1,252,169,241,210, 77|| 0.001
- ü©ñÒ-|, 32, 32, 32, 1,252,169,241,210|| 0.001
- ü©ñ-|, 32, 32, 32, 32, 1,252,169,241|| 0.019
- Ûù-|, 32, 32, 32, 32, 32, 1,219,249|| 0.005

c) Integer Numbers :
---------------------

-Û? -|,219, 63, 32, 32|| 3
-®@ -|, 1,174, 64, 32|| 11
- ¤A -|, 32, 1,164, 65|| 1
- O -|, 10, 32, 1, 79|| 3
-  -|, 13, 10, 32, 1|| 5
- -|, 76, 1, 13, 10|| 63
- -|, 32, 6, 1, 13|| 22

-Û? -|,219, 63, 32, 32|| 10
-®@ -|, 1,174, 64, 32|| 10
- ¤A-|, 32, 1,164, 65|| 10
- O-|, 10, 32, 1, 79|| 10
_ -|, 1, 13, 10, 32|| 38
- -|, 76, 1, 13, 10|| 10
- -|, 32, 6, 1, 13|| 10

-Û? -|,219, 63, 32, 32|| 16347
-®@ -|, 1,174, 64, 32|| 16558
- ¤A-|, 32, 1,164, 65|| 16804
- O-|, 10, 32, 1, 79|| 17020
- -|, 13, 10, 32, 1|| 16478
-  -|, 32, 6, 1, 13|| 16945

Please go thru above formats and let me know what are the steps of converting these ASCII values into interpreted values.

Thanks in advance.

Rajesh Parmar
 
I don't have time to examine and attempt to convert your samples; why don't you try to do it yourself?

As regards dates, look up DateTime structures; it may help.

For floating point numbers:
[ul]
[li]252,169,241,210, 77, 98, 80, 63 is hexadecimal fc a9 f1 d2 4d 62 50 3f;[/li]
[li]if considered as being in Intel (Little-Endian) format, this would be hex 3f 50 62 4d d2 f1 a9 fc[/li]
[li]If this is interpreted as an IEEE 64-bit double floating point value, the value is 1.0e-3, which is 0.001.[/li]
[/ul]

For integer values, you seem to have three different interpretations of the same values!
For the first of the third set of such values:
[ul]
[li]219, 63, 2, 32 is hexadecimal db 3f 20 20[/li]
[li]if you ignore the pair of trailing space (32 = hex 20) characters, this leaves hex db 3f[/li]
[li]if considered as being in Intel (Little-Endian) format, this would be hex 3f db[/li]
[li]if this is interpreted as a 16-bit (short) integer (either signed or unsigned format), the value is 16347.[/li]
[/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top