Go Premium for a chance to win a PS4. Enter to Win

x
Solved

# decimal convert  to ASCII -need math formula

Posted on 2008-06-23
Medium Priority
2,173 Views
How to convert decimal  to ASCII  -need math formula
0
Question by:al3457

LVL 53

Expert Comment

ID: 21846612
Depends what you mean. If you mean that you want to convert the decimal digits 0, 1, ..., 9 to their ASCII values, then you simply need to add 0x30 (or 48 in decimal) to it.

So, the character '0' has ASCII value 48, '1' is 49, etc. ... until '9' which has 57 as ASCII value.
0

LVL 32

Expert Comment

ID: 21847232
Your question is a little vague. How do you intend to use this "conversion" formula?
0

LVL 27

Accepted Solution

tliotta earned 2000 total points
ID: 21848884
al3457:

Normally, I would expect that this question involves a network-transport such as FTP where the "decimal" value is a packed-decimal field. The transport function has sent records from the file. The file has EBCDIC encoding on the sending side and ASCII on the receiving side. The transport then applies EBCDIC-to-ASCII translation on the entire record as a single string; this causes packed-decimal fields to be improperly translated as characters rather than as the half-bytes (nibbles) that make up the "BCD" portion of EBCDIC.

Under those circumstances, the ASCII translation to 'fix' the fields must take into account the particular conversion tables that were used in the network transport. A straight character conversion will not work.

So, the question requires some added clarification.

Please describe the circumstances. What platform will be running the conversion? Is this running on an ASCII or EBCDIC system? What does the data look like -- is it records in a file? fields in records in a file? single values passed in as parms? What languages are to be used?

Perhaps most importantly, is it really a conversion that's needed? Or would it be better to fix the problem that caused packed-decimal values to arrive on an ASCII system?

Tom
0

Author Comment

ID: 21868907
Thank you Tom,
You got it.It is ASCII
0

LVL 16

Expert Comment

ID: 21968406
Hi al3457,

Are you aware that FTPing from the AS/400 or using ODBC, is automatically converting fields from EBCDIC-to-ASCII, no conversion needed.
Just a remark :)

Regards,
Murph,
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article provides a brief introduction to tissue engineering, the process by which organs can be grown artificially. It covers the problems with organ transplants, the tissue engineering process, and the current successes and problems of the tec…
This article covers the basics of data encryption, what it is, how it works, and why it's important. If you've ever wondered what goes on when you "encrypt" data, you can look here to build a good foundation for your personal learning.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
###### Suggested Courses
Course of the Month7 days, 15 hours left to enroll