Questions tagged [ascii]

A character-encoding scheme based on the ordering of the English alphabet. ASCII stands for American Standard Code for Information Interchange.

ASCII codes represent text in computers, communications equipment, and other devices that use text. Most modern character-encoding schemes are based on ASCII, though they support many more characters than did ASCII.

ASCII includes definitions for 128 characters: 33 are non-printing control characters (now mostly obsolete) that affect how text and space is processed; 94 are printable characters, and the space is considered an invisible graphic. The most commonly used character encoding on the World Wide Web was US-ASCII until December 2007, when it was surpassed by UTF-8.

The following table contains the 128 ASCII characters.

Char  Dec  Oct Hex | Char Dec  Oct Hex | Char Dec  Oct Hex | Char Dec  Oct  Hex
(nul)   0 0000 x00 | (sp)  32 0040 x20 | @     64 0100 x40 | `      96 0140 x60
(soh)   1 0001 x01 | !     33 0041 x21 | A     65 0101 x41 | a      97 0141 x61
(stx)   2 0002 x02 | "     34 0042 x22 | B     66 0102 x42 | b      98 0142 x62
(etx)   3 0003 x03 | #     35 0043 x23 | C     67 0103 x43 | c      99 0143 x63
(eot)   4 0004 x04 | $     36 0044 x24 | D     68 0104 x44 | d     100 0144 x64
(enq)   5 0005 x05 | %     37 0045 x25 | E     69 0105 x45 | e     101 0145 x65
(ack)   6 0006 x06 | &     38 0046 x26 | F     70 0106 x46 | f     102 0146 x66
(bel)   7 0007 x07 | '     39 0047 x27 | G     71 0107 x47 | g     103 0147 x67
(bs)    8 0010 x08 | (     40 0050 x28 | H     72 0110 x48 | h     104 0150 x68
(ht)    9 0011 x09 | )     41 0051 x29 | I     73 0111 x49 | i     105 0151 x69
(nl)   10 0012 x0a | *     42 0052 x2a | J     74 0112 x4a | j     106 0152 x6a
(vt)   11 0013 x0b | +     43 0053 x2b | K     75 0113 x4b | k     107 0153 x6b
(np)   12 0014 x0c | ,     44 0054 x2c | L     76 0114 x4c | l     108 0154 x6c
(cr)   13 0015 x0d | -     45 0055 x2d | M     77 0115 x4d | m     109 0155 x6d
(so)   14 0016 x0e | .     46 0056 x2e | N     78 0116 x4e | n     110 0156 x6e
(si)   15 0017 x0f | /     47 0057 x2f | O     79 0117 x4f | o     111 0157 x6f
(dle)  16 0020 x10 | 0     48 0060 x30 | P     80 0120 x50 | p     112 0160 x70
(dc1)  17 0021 x11 | 1     49 0061 x31 | Q     81 0121 x51 | q     113 0161 x71
(dc2)  18 0022 x12 | 2     50 0062 x32 | R     82 0122 x52 | r     114 0162 x72
(dc3)  19 0023 x13 | 3     51 0063 x33 | S     83 0123 x53 | s     115 0163 x73
(dc4)  20 0024 x14 | 4     52 0064 x34 | T     84 0124 x54 | t     116 0164 x74
(nak)  21 0025 x15 | 5     53 0065 x35 | U     85 0125 x55 | u     117 0165 x75
(syn)  22 0026 x16 | 6     54 0066 x36 | V     86 0126 x56 | v     118 0166 x76
(etb)  23 0027 x17 | 7     55 0067 x37 | W     87 0127 x57 | w     119 0167 x77
(can)  24 0030 x18 | 8     56 0070 x38 | X     88 0130 x58 | x     120 0170 x78
(em)   25 0031 x19 | 9     57 0071 x39 | Y     89 0131 x59 | y     121 0171 x79
(sub)  26 0032 x1a | :     58 0072 x3a | Z     90 0132 x5a | z     122 0172 x7a
(esc)  27 0033 x1b | ;     59 0073 x3b | [     91 0133 x5b | {     123 0173 x7b
(fs)   28 0034 x1c | <     60 0074 x3c | \     92 0134 x5c | |     124 0174 x7c
(gs)   29 0035 x1d | =     61 0075 x3d | ]     93 0135 x5d | }     125 0175 x7d
(rs)   30 0036 x1e | >     62 0076 x3e | ^     94 0136 x5e | ~     126 0176 x7e
(us)   31 0037 x1f | ?     63 0077 x3f | _     95 0137 x5f | (del) 127 0177 x7f
6938 questions
119
votes
9 answers

Character reading from file in Python

In a text file, there is a string "I don't like this". However, when I read it into a string, it becomes "I don\xe2\x80\x98t like this". I understand that \u2018 is the unicode representation of "'". I use f1 = open (file1, "r") text =…
Graviton
  • 81,782
  • 146
  • 424
  • 602
115
votes
9 answers

Python Unicode Encode Error

I'm reading and parsing an Amazon XML file and while the XML file shows a ' , when I try to print it I get the following error: 'ascii' codec can't encode character u'\u2019' in position 16: ordinal not in range(128) From what I've read online…
Alex B
  • 1,185
  • 2
  • 8
  • 5
109
votes
13 answers

Integer ASCII value to character in BASH using printf

Character to value works: $ printf "%d\n" \'A 65 $ I have two questions, the first one is most important: How do I take 65 and turn it into A? \'A converts an ASCII character to its value using printf. Is the syntax specific to printf or is it…
user14070
105
votes
17 answers

Least used delimiter character in normal text < ASCII 128

For coding reasons which would horrify you (I'm too embarrassed to say), I need to store a number of text items in a single string. I will delimit them using a character. Which character is best to use for this, i.e. which character is the least…
Too embarrassed to say
103
votes
10 answers

What's the opposite of chr() in Ruby?

In many languages there's a pair of functions, chr() and ord(), which convert between numbers and character values. In some languages, ord() is called asc(). Ruby has Integer#chr, which works great: >> 65.chr A Fair enough. But how do you go the…
RJHunter
  • 2,829
  • 3
  • 25
  • 30
101
votes
8 answers

Regex any ASCII character

What is the regex to match xxx[any ASCII character here, spaces included]+xxx? I am trying xxx[(\w)(\W)(\s)]+xxx, but it doesn't seem to work.
ion
  • 1,141
  • 3
  • 9
  • 9
98
votes
3 answers

How to get a char from an ASCII Character Code in C#

I'm trying to parse a file in C# that has field (string) arrays separated by ASCII character codes 0, 1 and 2 (in Visual Basic 6 you can generate these by using Chr(0) or Chr(1) etc.) I know that for character code 0 in C# you can do the…
Jimbo
  • 22,379
  • 42
  • 117
  • 159
97
votes
9 answers

Convert string to ASCII value python

How would you convert a string to ASCII values? For example, "hi" would return [104 105]. I can individually do ord('h') and ord('i'), but it's going to be troublesome when there are a lot of letters.
Neal Wang
  • 1,177
  • 3
  • 10
  • 9
97
votes
13 answers

How can I pretty-print ASCII tables with Python?

I'm looking for a way to pretty-print tables like this: ======================= | column 1 | column 2 | ======================= | value1 | value2 | | value3 | value4 | ======================= I've found the asciitable library but it doesn't…
kdt
  • 27,905
  • 33
  • 92
  • 139
96
votes
8 answers

Convert binary to ASCII and vice versa

Using this code to take a string and convert it to binary: bin(reduce(lambda x, y: 256*x+y, (ord(c) for c in 'hello'), 0)) this outputs: 0b110100001100101011011000110110001101111 Which, if I put it into this site (on the right hand site) I get my…
sbrichards
  • 2,169
  • 2
  • 19
  • 32
95
votes
11 answers

Convert an int to ASCII character

I have int i = 6; and I want char c = '6' by conversion. Any simple way to suggest? EDIT: also i need to generate a random number, and convert to a char, then add a '.txt' and access it in an ifstream.
user963241
  • 6,758
  • 19
  • 65
  • 93
92
votes
9 answers

How do I convert a list of ascii values to a string in python?

I've got a list in a Python program that contains a series of numbers, which are themselves ASCII values. How do I convert this into a "regular" string that I can echo to the screen?
Electrons_Ahoy
  • 36,743
  • 36
  • 104
  • 127
91
votes
10 answers

ASCII Library for Creating "Pretty" Directory Trees?

Is there some *nix tool or perl/php library that will let you easily create directory tree visualizations that look like the following? www |-- private | |-- app | | |-- php | | | |-- classes | | | +-- scripts | | …
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
89
votes
7 answers

Invisible characters - ASCII

Are there any invisible characters? I have checked Google for invisible characters and ended up with many answers but I'm not sure about those. Can someone on Stack Overflow tell me more about this? Also I have checked a profile on Facebook and…
DonOfDen
  • 3,968
  • 11
  • 62
  • 112
87
votes
3 answers

Where is Python's "best ASCII for this Unicode" database?

I have some text that uses Unicode punctuation, like left double quote, right single quote for apostrophe, and so on, and I need it in ASCII. Does Python have a database of these characters with obvious ASCII substitutes so I can do better than…
joeforker
  • 40,459
  • 37
  • 151
  • 246