I2C SPI USB CAN eSPI Cable Testing View All Quick Start Guides User Manuals Software Downloads Knowledge Base Videos Case Studies App Notes White Papers Sales Support About Us
Products Blog Sales Support Contact Search
Binary vs ASCII – Their Relationship, Differences, and Embedded Applications
Jessica Hopkins

Binary and ASCII codes are two of the most commonly used coding systems in computing, yet they have some very distinct differences. Binary code is a system of binary digits (0s and 1s) that represent data or instructions in computers, while ASCII code is a set of characters represented by binary numbers, which makes it possible to transfer text-based information from one computer to another. In this blog post, we will take a closer look at binary and ASCII codes, exploring their relation, their differences, as well as providing examples of different applications.

What is Binary Code?

Binary data are binary strings representing values in computer memory, where each binary digit (or bit) can represent either off or on in a circuit, or a 0 or 1 for numerical data. Binary code assigns a pattern of binary digits, or bits, to each character. A group of eight bits put together is known as a byte, which is the basic unit of storage in most modern computer systems.

Binary code is structured in a way that can be read and executed as part of a larger computer program. Each binary number can represent a different instruction or piece of data stored on the computer. For example, binary code 01000001 would represent the letter "A".

Every piece of information that is processed by a computer, whether it be images, audio recordings, text documents, and other forms of media, is first converted into binary code, which the computer can then understand and manipulate. For example, when you type a letter on a keyboard, the computer translates that letter into a sequence of binary digits, which are stored in memory and processed by the computer's CPU.

What is ASCII and How Does it Relate to Binary Code?

ASCII was developed in order to standardize coding systems between computers, helping to minimize communication incompatibilities across different computer makes and models. ASCII code is used to represent text in computers and assigns standard numeric values to characters, including English letters (both upper-case and lower-case), numbers 0-9, punctuation marks such as parentheses, commas, asterisks etc., various control characters such as tab key etc., and blank space characters known as whitespace. These codes allow computers to translate from one language to another by changing the corresponding characters into their numerical equivalents. It also is used to translate computer text to human-readable text.

ASCII uses binary to represent the different characters. Each character is represented by 8 bits (1 byte) of binary code where each bit represents either a 0 or 1 depending on its position within the byte sequence. Standard ASCII is composed of 7 bits embedded within an 8-bit byte, with the last bit reserved as a “parity” bit to check for transmission errors. This allows for a total of 128 distinguished characters. Extended ASCII is also composed of 8 bits, but instead of using the eighth bit as a parity bit, it becomes available for extending the amount of supported characters, up to 256.

To encode a character using ASCII, you can look up its corresponding 7-bit binary code in the ASCII table. For example, the ASCII code for the letter 'A' is 65. To represent the letter 'A' in ASCII, the binary code 01000001 is used, which corresponds to the decimal value 65.

Using Binary and ASCII Together

By representing each ASCII character as a corresponding binary code, this allows computers to store and manipulate text in a binary format, which is the only format that digital devices can directly work with.

For example, when you type the letter 'A' on your keyboard, the computer converts it into its corresponding ASCII code (01000001) and stores it in its memory. When you open a text file or send an email containing the letter 'A', the computer reads the binary codes that represent the text and converts them back into human-readable characters using the ASCII encoding standard.

Using Binary and ASCII In Embedded Systems Applications

Binary and ASCII codes are used for specific purposes in computing applications. Because binary requires fewer transistors than other coding systems, it is often an efficient way to process data in embedded systems, making it ideal for control systems or embedded processors.

Mobile phone and computers with binary code Image by Gerd Altmann from Pixabay

Using Binary for CPU Applications

Going into this further, binary plays a key role in the operation of the CPU (Central Processing Unit) of a computer.

In the CPU, data and instructions are represented in binary form, as a sequence of 0s and 1s. This binary code is processed by the CPU, which performs arithmetic and logical operations on the data, based on the instructions provided by the program being executed. For instance, when a program is written in a high-level language, such as C or Python, it is translated into machine code, which consists of binary instructions that the CPU can understand and execute.

ASCII for Representing Text Data

ASCII provides a standardized and efficient way to represent text in embedded systems, allowing them to perform tasks such as displaying information on a screen, communicating with other systems, or processing user input.

For instance, for data transmission, ASCII is used to represent text that is transmitted between different systems or devices. As ASCII provides a standardized method for encoding each character numerically, it ensures that the same character is represented both ways across the communication channel.

Additionally, ASCII is helpful for engineers working with embedded systems that include a user interface. These user interfaces may display text characters on a screen, so human-readable characters encoded using ASCII help engineers to ensure that the characters are displayed correctly.

Similarly, in a system that generates log files or error messages, ASCII may be used to represent text data in a format that can be easily read and understood by humans. In this case, ASCII is often used to represent letters, numbers, punctuation marks, and other symbols, along with other control functions such as line breaks and indentation.

Total Phase Supports Memory Programming and Bus Monitoring in Binary, Hex, ASCII Formats

Total Phase offers host adapters for I2C/SPI memory programming and system emulation, as well as protocol analyzers for real-time I2C/SPI, USB, CAN, and eSPI bus monitoring.

Control Center Serial Software

Through the Control Center Serial Software, which provides access to all the features of the Promira Serial Platform (with I2C or SPI applications installed), the Aardvark I2C/SPI Host Adapter, and the Cheetah SPI Host Adapter, engineers can utilize the I2C Master/Slave or SPI Master/Slave module to write messages as a master or as a slave to send responses. This allows users to perform I2C/SPI system emulation to test different system components and their ability to operate as expected.

I2C Master tab of the I2C Module

 

In this module, users can enter the data into the message field directly, or the data can be loaded from a binary file by clicking on "Load". Conversely, the message can also be saved to a binary file by clicking on the "Save" button.

Data Center Software

In the Data Center Software, users can not only review the captured decoded data in the Transaction window, users can also review raw bytes of a transaction in the Data pane of the Details window, regardless of the protocol specific structure of the data. By default, the Data pane is configured to show the data in hexadecimal and ASCII format. Right clicking in the Data pane will bring up a context menu that allows users to configure the view by adding additional panes and adjusting the size, grouping, and radix of each pane. User can also save the captured data as a csv, binary, or tdc file for future analysis.

Details Window of Data Pane with hexadecimal and ASCII format

Flash Center Software

The Flash Center Software is a software package that allows engineers to quickly erase, program, and verify I2C- and SPI-based EEPROM and Flash memory chips that are interfaced through the Promira Serial Platform, Aardvark I2C/SPI Host Adapter, and Cheetah SPI Host Adapter.

The Data panel in the Flash Center Software includes a full-featured hex editor. The data can be specified in either hexadecimal or ASCII. The left side of the hex editor is the address offset of the data row. The middle section is the data represented in hexadecimal format. The right side is the data represented in ASCII format.

Data panel hex editor by hexadecimal or ASCII format

 

By using the Load File button, the contents of a binary, Intel Hex, or Motorola S-Record file can be read into the Data buffer.

Similarly, through the Save File button, the entire data buffer can also be saved to a binary, Intel Hex, or Motorola S-Record file.

These are just some of the ways our tools support the utilization of binary and ASCII code to allow engineers to debug and develop their embedded systems.

Conclusion

In conclusion, binary and ASCII codes are both essential elements of computing. While binary is the most basic form of coding that computers use to interpret data, ASCII provides a more comprehensive way for machines to understand human-readable text. Both binary and ASCII have their own strengths when it comes to coding applications, but understanding the differences between them can help developers create better programs with fewer errors. Ultimately, binary and ASCII work together as integral components in advancing the world of embedded systems.