Reputation: 936
I know that character encoding is the method by which bytes of data are represented in textual symbols such as English letters etc. But what I do not understand is where in the computer does the process of encoding takes place? Does it happen in the processor, in the OS, or where?
Upvotes: 0
Views: 333
Reputation: 16156
It's kind of both. Let's look at a small example: You can write yourself a very simple "OS" (better call it kernel, though even that isn't adequate for this stub) which doesn't think about any character encoding what so ever:
void kmain(void) {
volatile char * video = (volatile char *) 0xB8000;
*video++ = 65; // HERE
*video++ = 7;
}
When you compile and link that together with some small startup assembler code (which isn't about encodings, too) and run that on some x86 hardware, you'll see an "A" in the top left corner.
What happens here is that we write the value 65
into the memory location 0xB8000
, which is the location where the memory of the VGA graphics card (which is in text mode on startup) is mapped to. That piece of hardware interprets that value according to the ASCII table, and thus decides to print the shape of an "A". Why is it doing that? Well, it has some kind of indexed internal storage which stores the shape of the "A" at the index 65
. This shape has been put there by the manufacturer of the hardware, and might be implemented as "bytes in some memory" which I'd count as "software" or as fixed wired components which I'd count as hardware.
Going at a higher level, the characters you get displayed on your screen (assuming you're running a graphical environment) are most likely just fields of pixels for the graphics hardware, getting their meaning from the software (the display driver, or a fonts library like pango).
On the other hand, most printers differentiate between text and images, because they understand character encodings (so they get the value 65
, and not a field of pixels with the shape like the graphics card) and have optimized workflows for printing the characters they define.
Which brings me back to the initial claim: It's both a hardware and software issue, because character encodings are a code, a protocol defined to allow different components (be it hardware or software) to communicate with each other.
Upvotes: 1
Reputation: 21627
Maybe I could rephrase your question as: When does it matter whether the letter "A" or the character "9" is encoded in ASCII, EBCDIC or whatever.
That answer to that it hardware dependent.
Some processors have string instructions. For example, some (particularly order) processors have instructions that can add the strings "123" and "456" to get "579"
Some hardware displays strings on the screen. In that case, the encoding is dependent.
On the other hand, when the text is drawn in software (with fonts), the encoding only matters to the software.
For the most part these days, software encoding is a software issue. However, there are places where character encoding matters to the hardware.
Upvotes: 1