Custom Search
 


Use MySQL String Functions to Build Printable ASCII Character Chart



Printable ASCII Characters

ASCII stands for American Standard Code for Information Interchange. ASCII is the numerical representation of characters based on the English alphabet characters and non-printing characters. Table below lists the character encoding chart of 94 printable ASCII characters (excluding the space character), numbered from 33 to 126 in decimal base-10 number system.

Binary Octal Decimal Hexadecimal Character
100000403220space character
100001413321!
100010423422"
100011433523#
100100443624$
100101453725%
100110463826&
100111473927'
101000504028(
101001514129)
10101052422A*
10101153432B+
10110054442C,
10110155452D-
10111056462E.
10111157472F/
1100006048300
1100016149311
1100106250322
1100116351333
1101006452344
1101016553355
1101106654366
1101116755377
1110007056388
1110017157399
11101072583A:
11101173593B;
11110074603C<
11110175613D=
11111076623E>
11111177633F?
10000001006440@
10000011016541A
10000101026642B
10000111036743C
10001001046844D
10001011056945E
10001101067046F
10001111077147G
10010001107248H
10010011117349I
1001010112744AJ
1001011113754BK
1001100114764CL
1001101115774DM
1001110116784EN
1001111117794FO
10100001208050P
10100011218151Q
10100101228252R
10100111238353S
10101001248454T
10101011258555U
10101101268656V
10101111278757W
10110001308858X
10110011318959Y
1011010132905AZ
1011011133915B[
1011100134925C\
1011101135935D]
1011110136945E^
1011111137955F_
11000001409660`
11000011419761a
11000101429862b
11000111439963c
110010014410064d
110010114510165e
110011014610266f
110011114710367g
110100015010468h
110100115110569i
11010101521066Aj
11010111531076Bk
11011001541086Cl
11011011551096Dm
11011101561106En
11011111571116Fo
111000016011270p
111000116111371q
111001016211472r
111001116311573s
111010016411674t
111010116511775u
111011016611876v
111011116711977w
111100017012078x
111100117112179y
11110101721227Az
11110111731237B{
11111001741247C|
11111011751257D}
11111101761267E~

Build the ASCII table by using MySQL string functions

To create a table like shown above, you only need to create a table in MySQL that stores the 94 printable characters. The you use five MySQL string functions (BIN, OCT, ASCII, HEX, SPACE) to convert the printable characters to their representations in the different number system.

Name Number System
Binary Base 2
Octal Base 8
Decimal Base 10
Hexadecimal Base 16

Follow the steps below to build the ASCII table.

Step #1: Build a table to store the 94 printable characters

To copy and paste the query to SQLyog, use Firefox. Copying from Internet Explorer does not maintain the query format.

-- Build the table
CREATE TABLE `printable_char`
(
`id` tinyint(3) unsigned NOT NULL,
`single_char` char(1) NOT NULL default '',
PRIMARY KEY (`id`)
);

Step #2: Bulk Insert the 94 printable characters

insert  into `printable_char`(`id`,`single_char`) 
values (1,'!'),(2,'\"'),(3,'#'),(4,'$'),(5,'%'),(6,'&'),(7,'\''),(8,'('),
(9,')'),(10,'*'),(11,'+'),(12,','),(13,'-'),(14,'.'),(15,'/'),(16,'0'),
(17,'1'),(18,'2'),(19,'3'),(20,'4'),(21,'5'),(22,'6'),(23,'7'),(24,'8'),
(25,'9'),(26,':'),(27,';'),(28,'<'),(29,'='),(30,'>'),(31,'?'),(32,'@'),
(33,'A'),(34,'B'),(35,'C'),(36,'D'),(37,'E'),(38,'F'),(39,'G'),(40,'H'),
(41,'I'),(42,'J'),(43,'K'),(44,'L'),(45,'M'),(46,'N'),(47,'O'),(48,'P'),
(49,'Q'),(50,'R'),(51,'S'),(52,'T'),(53,'U'),(54,'V'),(55,'W'),(56,'X'),
(57,'Y'),(58,'Z'),(59,'['),(60,'\\'),(61,']'),(62,'^'),(63,'_'),(64,'`'),
(65,'a'),(66,'b'),(67,'c'),(68,'d'),(69,'e'),(70,'f'),(71,'g'),(72,'h'),
(73,'i'),(74,'j'),(75,'k'),(76,'l'),(77,'m'),(78,'n'),(79,'o'),(80,'p'),
(81,'q'),(82,'r'),(83,'s'),(84,'t'),(85,'u'),(86,'v'),(87,'w'),(88,'x'),
(89,'y'),(90,'z'),(91,'{'),(92,'|'),(93,'}'),(94,'~');

Step #3: Create the query to retrieve the 94 printable characters and convert them to their other representations.

/*
There are two SELECT statements unioned together.
The first one returns values for space character.

The second one build the ASCII table for
the 94 printable characters.
*/
SELECT BIN(ASCII(SPACE(1))) AS binary_val,
OCT(ASCII(SPACE(1))) AS octal_val,
ASCII(SPACE(1)) AS decimal_val,
HEX(SPACE(1)) AS hex_val,
'SPACE character' AS single_char
UNION ALL
SELECT BIN(ASCII(single_char)) AS binary_val,
OCT(ASCII(single_char)) AS octal_val,
ASCII(single_char) AS decimal_val,
HEX(single_char) AS hex_val,
single_char
FROM printable_char;

More detailed information about the five string functions (BIN, OCT, ASCII, HEX, SPACE) used in the query above, refer to MySQL String Functions section.




Copyright© GeeksEngine.com



Other Recent Articles from the Web Development category:

1.Java / JSP lost session value on redirect - FIXED
2.Fix the problem with PHP5 XML removeChild() method
3.How to integrate PHP HTML Help .chm file with Crimson Editor
4.How to Connect to a MySQL Database from PHP
5.Five ways to create include path for PHP
6.How to use Date and Time data as integer value in PHP and MySQL
7.Absolute Path and Relative Path Explained

Copyright © 2017 GeeksEngine.com. All Rights Reserved.

This website is hosted by HostGator.

No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it.

 
Home | Feedback | Terms of Use | Privacy Policy