The correct spelling is "ascii". See "man ascii".
What software are you using to view the file which produces the character record you describe?
Recording characters as two-digit? decimal is much too weird. Can you post a definitive unix hexadecimal dump af a couple of records such that the bit pattern of the data is 100% clear.
You'll need to add a separator character (space or comma etc.) to delimit individual ASCII decimal values. Otherwise it's difficult to build the string from your input data.
Can you provide sample input and sample output with an explanation of the process required to convert input to output? Then we can consider code for the conversion.
My main issue was with ambiguous data. An ASCII character equates to any decimal value in the range 0-255 . Unless you cut the target range severely it is impossible to pick characters in their decimal representation out of a lengthy stream without delimiters.
Consider:
2222222
It is however 100% definite with hexadecimal characters (providing that all leading zeros are stated).
This isn't a direct answer to how to do it, I last was involved at this level in converting ASCII to Hollerith, round holes in tape to rectangular holes in cards, but an understanding of what is represented might help you.
ASCII data is 2 channels of control and 5 channels of data or basically 4 blocks of 32 possibilities. The 0 to 32 block with no control value consists of control codes. The 32 block with channel 6 are printable special characters and numbers, with channel 7 are uppercase alphabetic, and with 6 plus 7 are lower case alphabetic. The numeric representation of any character is the number of the control block*32+the value represented by the 5 channels.
$
$ echo "729711810132973278105991013268971213233" |
> perl -lne 'chomp($x=$_);
> do { $inc = substr($x,$i,1)<2 ? 3 : 2; push @s,substr($x,$i,$inc); $i+=$inc
> } while $i<length($x); print pack("C*",@s)'
Have a Nice Day !
$
And another way, especially if that string is too long:
$ ##
$ echo "729711810132973278105991013268971213233" |
> perl -ne 'chomp($x=$_);
> do {if (substr($x,$i,1)<2) {$e=substr($x,$i,3);$i+=3}
> else {$e=substr($x,$i,2);$i+=2} printf("%c",$e)
> } while $i<length($x); print "\n"'
Have a Nice Day !
$
As a side note, this seems to be overkill for a simple task. It's kind of hard to imagine why the source system could not generate an array or a delimited string thereby marking boundaries for individual characters.
Surely Hollerith (ISO) pre-dates ASCII by many years.
Edfair is quite correct in the origins of the collating sequence which relied on the position of holes in the punch card to perform a sort. Without a Hollerith card sorter what would the early James Bond movies use to represent a computer?
---------------------------------------------------------------------
Thanks you very much!
actully I have been asked to convert data into ascii stream with no delimiters.The data is store in a file say "codefile", it contains data like this
and contains multuiple lines
Have a Nice Day!
I wrote follwing script
-------------------------------------------------------
#!/bin/bash
while read -n1 char
do
printf "%d" \'$char
done < codefile
----------------------------------------------------------
Output is
./coder.sh
72971181010970781059910106897121330
But instead of spaces it prints 0(bolded in upper output), Which is supposed to be 32 (Ascii vale of space),Also it print an exta 0 at the end (marked as red).
Can any one please help me how to debug, Does printf not take special charaters as variable to print ? or the variable is not able to store the spcial characters like space?..Please help
Methyl,
IBM's data transmission protocol was EBCDIC using 8 track tape through their 047 tape to card machine. One customer wanted to use a KSR33 to create ASCII tape and another to receive and generate a duplicate tape then convert the data to punch cards through their 047. To keep the machine whole, for later sale or lease, I hung a relay rack on the back to handle the decoding, bringing channel signals out and sending Hollerith in.
I would assume that IBM eventually worked up stuff to handle ASCII but at the time there wasn't anything in their playbook.
I'm confused. One part of the post says that the source is an A/N data stream and the requested output is to be a stream of ASCII characters. Then stuff shows like decimal representation but is incomplete.
If I'm confused, maybe someone else is too.
My posting here is more about my education than an attempt to help. I've done this in a unix to dos environment but handled it on the dos side.
Thanks you very much!
####This is a separate request###
I have been asked also to convert data into ascii stream with no delimiters.The data is store in a file say "codefile", it contains data like this
Have a Nice Day!
I wrote follwing script
-------------------------------------------------------
#!/bin/bash
while read -n1 char
do
printf "%d" \'$char
done < codefile
----------------------------------------------------------
Output is
./coder.sh
72971181010970781059910106897121330
But instead of spaces it prints 0(bolded in upper output), Which is supposed to be 32 (Ascii vale of space),Also it print an exta 0 at the end (marked as red).
Can any one please help me how to debug, Does printf not take special charaters as variable to print ? or the variable is not able to store the spcial characters like space?..Please help
$
$ cat codefile
Hi! How are you?
Have a nice day!
Also sprach Zarathustra.
$
$ perl -lne 'chomp; @x=unpack("C*",$_); print @x' codefile
7210533327211111932971141013212111111763
729711810132973211010599101321009712133
65108115111321151121149799104329097114971161041171151161149746
$
If you are unfamiliar with the syntax and function, then have a look at the manual pages of the Perl documentation at The Perl Directory - perl.org
If you have no idea of what the heck Perl is, then check out books by O'Reilly Media for a good introduction (provided you have the willingness to learn, of course).