LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-04-2019, 04:15 AM   #1
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
How does the ASCII character set "draw" characters?


I've been watching the video's GazL linked to in another thread of mine, and Caleb talks about how C uses the ASCII character set, but I have a few questions...

While I'm not really sure how to ask my questions in a way that will make sense, so I'll start off with what I *think* I know first, and hopefully that can make it clear exactly what I'm not sure about. So here's what I *think* I know: C uses ASCII to know what the allowed characters are, and a character set basically defines the "allowed characters". Each "allowed character" has both an ASCII number and a corresponding binary (base2) number. Correct? Assuming I'm right in saying that; I get that and that's how C "knows" what character is what, and the computer deals in numbers and has no concept of spoken languages.

But while I've tried to search for the answers to my questions below, all my searches have failed me. More precisely, have only told me what I think I already (being what I said above).

So now on to my questions: Where is the ASCII character set itself stored? Where does the computer actually "look" to lookup a letter if the computer only knows binary? As it doesn't seem to me that it looks at a file on the hard/SSD/whatever drive, let alone a USB stick, etc.

Does the ASCII character set itself tell the computer which pixels to "light up" on the screen to form say for example, the letter "A"? In other words; how does the character set "tell" the computer how to draw a given letter, like for example, and once again an "A"?

Because, and from what I've read, if you're talking about a font, well the font file tells the computer how to draw a given letter. So that seems to explain it in regards to fonts, like for example "Times New Roman". But how does it work in regards to ASCII? That's what I'm not getting.

Hopefully I make at least some sense there. Thanks for any help with that.

James
 
Old 12-04-2019, 04:33 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,851
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
I think you are indeed referring to fonts (and font-files).

Every font-file contains zero or more character-images, these images can be 'accessed' via a code; nowadays it is typically Unicode, which has a theoretical range of 1,000,000+ characters. (Often expressed in hexadecimal prefixed with 'U+'; eg U+41 is the code of 'A'; U+1F354 is the code of a hamburger-emoji)

Of course actual font-files contain much less characters; if your try to access a character that isn't in the supported set, you get a substitute character (a ?question mark, for example).

Now the first 128 code if Unicode is equal to ASCII-code
Also the first 256 code of Unicode is equal to ISO-8859-1 code
 
1 members found this post helpful.
Old 12-04-2019, 05:01 AM   #3
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
No, I was saying that it makes sense that a font file tells the computer how to draw a particular character. But this does not answer my questions above. So forget I said anything about font files, and/or fonts.

I'm talking about ASCII, so let's assume font files don't exist.
 
Old 12-04-2019, 05:03 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,851
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
Okay, so exactly what is your question regarding ASCII?
 
Old 12-04-2019, 05:20 AM   #5
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
The same two questions I asked in post #1.

I'm not trying to be rude, but if I knew of a better way to ask them; then I likely wouldn't be asking them to begin with - so I'm honestly not sure how else to ask them.
 
Old 12-04-2019, 06:02 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,876
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
How it gets drawn to the screen is done by a driver.
 
1 members found this post helpful.
Old 12-04-2019, 06:10 AM   #7
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,882

Rep: Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988Reputation: 4988
The computer program simply tells the tty device to output a character with a certain ascii value and the hardware does the rest.

In the old days, that tty output might go to a serially attached vt100 terminal, or teletype. These days it's more likely to go to a terminal emulator, but it's essentially doing the exact same thing that it was doing 50 years ago, only in emulation software.

In X11, font rendering is done by the various libraries that provide that function, but as a general rule they all take ascii/or unicode strings as input and the fonts have maps embedded within them which map ascii values to glyph index numbers.
 
2 members found this post helpful.
Old 12-04-2019, 06:11 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,851
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
> The same two questions I asked in post #1.
> How it gets drawn to the screen is done by a driver.

That's what font-files are good for. The MDA/CGA/EGA/VGA card in your PC also contains such font-files.
https://en.wikipedia.org/wiki/VGA-co...ext_mode#Fonts

See also: https://www.google.com/search?q=bitmap+font&tbm=isch

Last edited by NevemTeve; 12-04-2019 at 06:24 AM.
 
1 members found this post helpful.
Old 12-04-2019, 06:21 AM   #9
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
Many thanks to you RT & GazL!

I think you both have answered my question. But I would like to make sure I understand the answer though

So basically, the ASCII table it's very self only exists on paper or on the Internet in HTML/web page form. But the graphics driver "knows" what the ASCII code means, it gets converted to binary, and the graphics driver draws the character(s) on the screen accordingly? Is that basically how it goes?

(without getting into font rendering - although VERY nice explanation of X11 font rendering GazL!)
 
Old 12-04-2019, 06:34 AM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,851
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
An example: say, you have a 8x8 pixel character-cell, and you have a character with code 65 (0x41), and you see this caracter:
Code:
........
..###...
.#...#..
.#####..
.#...#..
.#...#..
.#...#..
........
Characters of this size can be encoded in eight bytes (64bits), eg (all hexadecimal):
Code:
84210000
00008421
........ 00
..###... 38
.#...#.. 44
.#####.. 7C
.#...#.. 44
.#...#.. 44
.#...#.. 44
........ 00
You can assume that your font-file (be it software or hardware) contains these bytes somewhere: 00, 38, 44, 7c, 44, 44, 44, 00

Now 'somewhere' is BASE_ADDRESS+(character_code*bytes_per_character) that is BASE_ADDRESS+65*8 for code=65
 
1 members found this post helpful.
Old 12-04-2019, 07:17 AM   #11
Geist
Member
 
Registered: Jul 2013
Distribution: Slackware 14 / current
Posts: 442

Rep: Reputation: 196Reputation: 196
It's completely arbitrary (well, not really, people do generally try to make things sensible) at the end of the day, from hardware to software.
Everything a computer does is because people have designed them and the data that way.

Everthing is a number, what the numbers do is defined by people, a screen is just a grid with indices, what goes into the indices someone has defined and written/burned into some chip (it's more complex of course, etc) or a punchcard or other medium.

It's literally just lookups at the end of the day. Now, basic computer functionality usually follows a Turing machine, etc, a set of instructions and what to do with them, an that's basically it.

It's lookups at memory addresses and sending data from there somewhere else, in some desired format, like pulsing some signal over a wire into a screen/monitor, where that data gets used as per its own "arbitrarily set up by humans" rules.

The answer to the question why the computer "knows" what ASCII is is pretty much the same answer to you knowing that a computer can "know" to begin with.
It has the capability to "Know" because it was given that ability.

Everything is designed to pan out the way it pans out by applying knowledge about semiconductors, electricity and so forth into a machine that does a specific task (hopefully) to the intended specifications.
That might sound like some sort of copout, non answer, but at the end of the day, it's pretty much the core of the whole thing.
People have thought up a standard of characters to use, then put away a range of numbers for these characters to be used in the context of "character handling", and then placed data the computer pulls from when a number of in that range comes up.

Decimal 65? We have decided that that shall be the value for "A".
It has come up! Jump to the table that contains the data the graphics system can use to light up specific pixels and draw that A!

Etc.

And sometimes the location of that data is editable, it's how old 8bit computers like the commodore 64 had one way of doing graphics.
The programmer edited the pixel data of the letters into something more pictoresque, and then constructed artwork out of that.

What then was ASD DSA then became, for example ▓▒░ ░▒▓ (only in this case these semi solid blocks are part of an ASCII flavor, but I'm sure you get the idea)

Last edited by Geist; 12-04-2019 at 08:01 AM.
 
Old 12-04-2019, 08:09 AM   #12
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,876
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by jsbjsb001 View Post
Many thanks to you RT & GazL!

I think you both have answered my question. But I would like to make sure I understand the answer though

So basically, the ASCII table it's very self only exists on paper or on the Internet in HTML/web page form. But the graphics driver "knows" what the ASCII code means, it gets converted to binary, and the graphics driver draws the character(s) on the screen accordingly? Is that basically how it goes?

(without getting into font rendering - although VERY nice explanation of X11 font rendering GazL!)
The ASCII table exists, doesn't matter if it's in code, hard-wired into a graphics chip, or other, it exists. Splitting some fine hair about it is nonsense.

Here's a problem: "without getting into font rendering"

You sort of can't, at least for modern day.

Old, old school there were no fonts. The concepts are still similar.

People decided that they had X by Y resolution of pixels to draw a character.

They picked the minimum they could because displays were not high resolution and also costly.

Side note: This is also one of the reasons why there were (and still are) seven segment displays those don't use pixels.

Screen rendering of characters uses pixels which equates also to the resolution of a screen.

If you stack a bunch of pixels in a column, you draw number 1, or the letter l, or a capital I (potentially - it all depends on the eye of the beholder).

If you assume to use a rectangle of pixels to draw your characters, say 10x8 you can draw numbers and characters and they'll look simplistic and drawn in a raw fashion, but that's how it's done to define it. Fonts just improve this by providing the information on a "per resolution" basis, and also do specify the minimum resolution required to render the font.

Further you'll notice that things like the system font are fixed fonts and it looks like a machine, but the more typical fonts you see are non-fixed, variable, where they resolve the amount of space around them so that the m and the l letters do not appear unnatural when you see them.

As an example, the [code] blocks we use here on LQ give you a fixed font so that a bunch of spaces really does match the characters and every character receives the same space between digits and for each digit.

When you're on a screen and the screen resolution is 240x320 in pixels, if you use 10x10 pixels to represent a character, you end up being only able to put 24 characters per line.

With higher resolutions as well as things like subpixel rendering you can improve the visible characters so that they do not look like a bunch of dots.

I don't know what they use today for high resolution, but some fonts require things like 24x24 pixels or something close to show them. I'm talking various languages like Chinese where they are pictures versus characters.

How does this occur on an actual computer?
  1. Graphics hardware
  2. Driver software
If you really want to learn all that, help yourself.

But do not assume things are exact or that you can make a statement like you did about the ASCII table.

Go to a very fundamental display on a hobby board, with no operating system. In that case the programmer literally does draw pixel characters to show what they want to show.

The difference is that with a full up computer, there are hardware assist devices and also there need to be drivers to control them, which understand how much or how little information is needed to draw characters properly.
 
2 members found this post helpful.
Old 12-04-2019, 08:27 AM   #13
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Original Poster
Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
I don't think I'm at the stage of understanding graphics drivers, let alone the ins and outs of graphics hardware yet RT

But, this is what I'm wondering; say I have a program that sends the ASCII code of "A" to the tty device; what's the process beyond that? Does it go straight to the graphics hardware, or does it go to the graphics driver and that tells the hardware how to draw the "A", and the graphics hardware renders it on the screen?

So is it; app > tty device > hardware.
Or app > tty device > graphics driver (which tells the hardware how to draw the letter "A") > graphics hardware ?

This is what I'm wondering.
 
Old 12-04-2019, 08:27 AM   #14
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,494
Blog Entries: 19

Rep: Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410Reputation: 4410
As far as I can remember, the characters you see in a console display are stored in video memory. They are accessed by a number, the ASCII code for that character. So if the ASCII code for 'A' is sent, the console pulls the appropriate picture out of video memory and displays it. That's why text is so economical to store. You don't have to store the actual characters, just their ID numbers. Of course there are different sets of numbers nowadays corresponding to ASCII, iso-latin, utf8 and so on. And there are different console fonts just as there are different X fonts. You can find the former in /usr/share/kbd and the latter in /usr/share/fonts.

The X version is more complicated because the characters have to be drawn onto an overall picture which is then displayed as a unit, whereas with the console, each character is displayed directly onto a rectangular portion of the screen. I remember that at work, back in the '80s, we used remote terminals with quite a low line transmission speed and you could actually see the text being written out line by line as the characters came over.

Last edited by hazel; 12-04-2019 at 08:29 AM.
 
1 members found this post helpful.
Old 12-04-2019, 09:01 AM   #15
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,851
Blog Entries: 1

Rep: Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868Reputation: 1868
The VGA-card in your PC supports text-modes and graphics-modes. In text-modes the image of characters are drawn by the VGA-card itself; in graphics-modes programs like X server draw the character-images.
 
2 members found this post helpful.
  


Reply

Tags
ascii, character set, characters


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] GLib: Conversion from character set 'UTF8' to 'ASCII' is not supported. wesley_q Linux - Software 1 06-16-2015 04:58 AM
ASCII, ANsI, create my own Extended character set??? AngryAngry Programming 4 05-05-2014 05:29 PM
[SOLVED] What is the difference between "ASCII English text" and "ASCII text" ??? astanton Slackware 13 08-05-2011 06:14 AM
To know the function on checking whether a character is ascii or unicode character. murugesan Programming 2 01-23-2009 01:07 PM
I cant draw a ASCII table in c++ shell console DonnyYangR Programming 6 05-23-2008 06:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration