Serial Port Complete - Latest Microcontroller projects

(lily) #1

Chapter 2


The Unicode standard has details about how to convert code points into code
units using each encoding method. A .NET application can use methods that
perform the encoding and decoding automatically. Chapter 9 has more about
working with text in .NET applications.

! 
9


Treating data as text is the obvious choice for transferring strings or files that
contain text. But you can also use text to transfer binary data by expressing the
data in ASCII Hex format. Each byte is represented by a pair of ASCII codes
that represent the byte’s two hexadecimal characters, which are in the range 0–9
and A–F. ASCII Hex can represent any numeric value using only the ASCII
codes 30h–39h (to represent values 00h–09h) and 41h–46h (to represent values
0Ah–0Fh). Code that allows lower-case letters might also use 61h–66h (to rep-
resent 0ah–0fh).
Instead of sending one byte to represent a value from 0 to 255, the transmitting
computer sends two bytes, one for each character in the hex number that repre-
sents the byte. The receiving computer can convert the characters to numeric
values or use the data in any way.
For example, consider the decimal number:
225
Expressed as a binary number, it’s:
11100001
In hexadecimal, it’s:
E1
The ASCII codes for “E” and “1” are:
45h 31h
So the binary representation of this value in ASCII hex consists of these two
bytes:
01000101 00110001
A serial link using ASCII Hex format would send the decimal value 225 by
transmitting the two bytes above.
A disadvantage of using ASCII hex is that each byte value requires two charac-
ters so data takes twice as long to transfer. Also, in most cases the application at
each end must convert between ASCII hex and binary.
Free download pdf