# Binary signals and coding in computing the presentations

The precise 4-bit encoding may vary however, for technical reasons, see Excess-3 for instance. BCD's main virtue is its more accurate representation and rounding of decimal quantities as well as an ease of conversion into human-readable representations, in comparison to binary positional systems.

BCD's principal drawbacks are a small increase in the complexity of the circuits needed to implement basic arithmetics and a slightly less dense storage.

Although BCD per se is not as widely used as in the past and is no longer implemented in newer computers' instruction sets such as ARM ; x86 does not support BCD instructions in long mode any more , decimal fixed-point and floating-point formats are still important and continue to be used in financial, commercial, and industrial computing, where subtle conversion and fractional rounding errors that are inherent in floating point binary representations cannot be tolerated.

BCD takes advantage of the fact that any one decimal numeral can be represented by a four bit pattern. The most obvious way of encoding digits is "natural BCD" NBCD , where each decimal digit is represented by its corresponding four-bit binary value, as shown in the following table. This is also called "" encoding. Other encodings are also used, including so-called "" and ""—named after the weighting used for the bits—and " Excess-3 ".

As most computers deal with data in 8-bit bytes , it is possible to use one of the following methods to encode a BCD number:. As an example, encoding the decimal number 91 using unpacked BCD results in the following binary pattern of two bytes:. Hence the numerical range for one unpacked BCD byte is zero through nine inclusive, whereas the range for one packed BCD is zero through ninety-nine inclusive.

To represent numbers larger than the range of a single byte any number of contiguous bytes may be used. For example, to represent the decimal number in packed BCD, using big-endian format, a program would encode as follows:.

Note that the most significant nibble of the most significant byte is zero, implying that the number is in actuality Also note how packed BCD is more efficient in storage usage as compared to unpacked BCD; encoding the same number with the leading zero in unpacked format would consume twice the storage.

Shifting and masking operations are used to pack or unpack a packed BCD digit. Other logical operations are used to convert a numeral to its equivalent bit pattern or reverse the process. BCD is very common in electronic systems where a numeric value is to be displayed, especially in systems consisting solely of digital logic, and not containing a microprocessor.

By employing BCD, the manipulation of numerical data for display can be greatly simplified by treating each digit as a separate single sub-circuit. This matches much more closely the physical reality of display hardware—a designer might choose to use a series of separate identical seven-segment displays to build a metering circuit, for example.

If the numeric quantity were stored and manipulated as pure binary, interfacing to such a display would require complex circuitry. Therefore, in cases where the calculations are relatively simple, working throughout with BCD can lead to a simpler overall system than converting to and from binary. Most pocket calculators do all their calculations in BCD. The same argument applies when hardware of this type uses an embedded microcontroller or other small processor.

Often, smaller code results when representing numbers internally in BCD format, since a conversion from or to binary representation can be expensive on such limited processors. For these applications, some small processors feature BCD arithmetic modes, which assist when writing routines that manipulate BCD quantities.

In packed BCD or simply packed decimal , each of the two nibbles of each byte represent a decimal digit. Most implementations are big endian , i. The lower nibble of the rightmost byte is usually used as the sign flag, although some unsigned representations lack a sign flag. As an example, a 4-byte value consists of 8 nibbles, wherein the upper 7 nibbles store the digits of a 7-digit decimal value and the lowest nibble indicates the sign of the decimal integer value. Other allowed signs are A and E for positive and B for negative.

Most implementations also provide unsigned BCD values with a sign nibble of F. Burroughs systems used D for negative, and any other value is considered a positive sign value the processors will normalize a positive sign to C.

No matter how many bytes wide a word is, there are always an even number of nibbles because each byte has two of them. Note that, like character strings, the first byte of the packed decimal — with the most significant two digits — is usually stored in the lowest address in memory, independent of the endianness of the machine. The extra storage requirements are usually offset by the need for the accuracy and compatibility with calculator or hand calculation that fixed-point decimal arithmetic provides.

Denser packings of BCD exist which avoid the storage penalty and also need no arithmetic operations for common conversions. Ten's complement representations for negative numbers offer an alternative approach to encoding the sign of packed and other BCD numbers. In this case, positive numbers always have a most significant digit between 0 and 4 inclusive , while negative numbers are represented by the 10's complement of the corresponding positive number.

As a result, this system allows for, a bit packed BCD numbers to range from ,, to 49,,, and -1 is represented as As with two's complement binary numbers, the range is not symmetric about zero. These languages allow the programmer to specify an implicit decimal point in front of one of the digits. The decimal point is not actually stored in memory, as the packed BCD storage format does not provide for it.

Its location is simply known to the compiler and the generated code acts accordingly for the various arithmetic operations. If a decimal digit requires four bits, then three decimal digits require 12 bits. However, since 2 10 1, is greater than 10 3 1, , if three decimal digits are encoded together, only 10 bits are needed.

The latter has the advantage that subsets of the encoding encode two digits in the optimal seven bits and one digit in four bits, as in regular BCD. Some implementations, for example IBM mainframe systems, support zoned decimal numeric representations. Each decimal digit is stored in one byte, with the lower four bits encoding the digit in BCD form. The upper four bits, called the "zone" bits, are usually set to a fixed value so that the byte holds a character value corresponding to the digit.

For signed zoned decimal values, the rightmost least significant zone nibble holds the sign digit, which is the same set of values that are used for signed packed decimal numbers see above. These characters vary depending on the local character code page setting. The IBM series are character-addressable machines, each location being six bits labeled B, A, 8, 4, 2 and 1, plus an odd parity check bit C and a word mark bit M. For encoding digits 1 through 9 , B and A are zero and the digit value represented by standard 4-bit BCD in bits 8 through 1.

For most other characters bits B and A are derived simply from the "12", "11", and "0" "zone punches" in the punched card character code, and bits 8 through 1 from the 1 through 9 punches. A "12 zone" punch set both B and A , an "11 zone" set B , and a "0 zone" a 0 punch combined with any others set A.

Thus the letter A , which is 12,1 in the punched card format, is encoded B,A,1. This allows the circuitry to convert between the punched card format and the internal storage format to be very simple with only a few special cases.

One important special case is digit 0 , represented by a lone 0 punch in the card, and 8,2 in core memory. The memory of the IBM is organized into 6-bit addressable digits, the usual 8, 4, 2, 1 plus F , used as a flag bit and C , an odd parity check bit.

BCD alphamerics are encoded using digit pairs, with the "zone" in the even-addressed digit and the "digit" in the odd-addressed digit, the "zone" being related to the 12 , 11 , and 0 "zone punches" as in the series.

A variable length Packed BCD numeric data type is also implemented, providing machine instructions that perform arithmetic directly on packed decimal data. All of these are used within hardware registers and processing units, and in software. The MicroVAX and later VAX implementations dropped this ability from the CPU but retained code compatibility with earlier machines by implementing the missing instructions in an operating system-supplied software library.

This is invoked automatically via exception handling when the no longer implemented instructions are encountered, so that programs using them can execute without modification on the newer machines.

Although the two graphs look different in their appearance, notice that they repeat themselves at equal time intervals. Electrical signals or waveforms of this nature are said to be periodic. Generally,a periodic wave representing a signal can be described using the following parameters Amplitude A Frequency f periodic time T Amplitude A: It is measured in hertz. When a digital signal is to be sent over analog telephone lines e.

This is done by connecting a device called a modem to the digital computer. This process of converting a digital signal to an analog signal is known as modulation. On the receiving end, the incoming analog signal is converted back to digital form in a process known as demodulation. Data and instructions cannot be entered and processed directly into computers using human language. Any type of data be it numbers, letters, special symbols, sound or pictures must first be converted into machine-readable form i.

Due to this reason, it is important to understand how a computer together with its peripheral devices handles data in its electronic circuits, on magnetic media and in optical devices. Data representation in digital circuits Electronic components, such as microprocessor, are made up of millions of electronic circuits.

This concept can be compared to switching on and off an electric circuit. This forms a basis for describing data representation in digital computers using the binary number system. Data representation on magnetic media The laser beam reflected from the land is interpreted, as 1.

The laser entering the pot is not reflected. This is interpreted as 0. The reflected pattern of light from the rotating disk falls on a receiving photoelectric detector that transforms the patterns into digital form. Magnetic technology is mostly used on storage devices that are coated with special magnetic materials such as iron oxide.

It has proved difficult to develop devices that can understand natural language directly due to the complexity of natural languages.

All forms of data can be represented in binary system format. Other reasons for the use of binary are that digital devices are more reliable, small and use less energy as compared to analog devices.

Bits, bytes, nibble and word The terms bits, bytes, nibble and word are used widely in reference to computer memory and data size. It is the basic unit of data or information in digital computers. A byte is considered as the basic unit of measuring memory size in computer. The term word length is used as the measure of the number of bits in each word. For example, a word can have a length of 16 bits, 32 bits, 64 bits etc.

Computers not only process numbers, letters and special symbols but also complex types of data such as sound and pictures. However, these complex types of data take a lot of memory and processor time when coded in binary form. This limitation necessitates the need to develop better ways of handling long streams of binary digits. Higher number systems are used in computing to reduce these streams of binary digits into manageable form.

This helps to improve the processing speed and optimize memory usage. Number systems and their representation A number system is a set of symbols used to represent values derived from a common base or radix. As far as computers are concerned, number systems can be classified into two major categories: Decimal number system has ten digits ranging from Because this system has ten digits; it is also called a base ten number system or denary number system.

A decimal number should always be written with a subscript 10 e. X 10 But since this is the most widely used number system in the world, the subscript is usually understood and ignored in written work. However ,when many number systems are considered together, the subscript must always be put so as to differentiate the number systems. The magnitude of a number can be considered using these parameters. Absolute value Place value or positional value Base value The absolute value is the magnitude of a digit in a number.

The place value of a digit in a number refers to the position of the digit in that number i. The total value of a number is the sum of the place value of each digit making the number. The base value of a number also k known as the radix , depends on the type of the number systems that is being used. The value of any number depends on the radix. It uses two digits namely, 1 and 0 to represent numbers. Octal number system Consists of eight digits ranging from A hexadecimal number can be denoted using 16 as a subscript or capital letter H to the right of the number.

For example, 94B can be written as 94B16 or 94BH. Further conversion of numbers from one number system to another To convert numbers from one system to another.

Converting between binary and decimal numbers. Converting octal numbers to decimal and binary form. Converting hexadecimal numbers to decimal and binary form.

First, write the place values starting from the right hand side. Write each digit under its place value. Multiply each digit by its corresponding place value. Add up the products. The answer will be the decimal number in base ten.

The binary equivalent of the fractional part is extracted from the products by reading the respective integral digits from the top downwards as shown by the arrow next page.

Combine the two parts together to set the binary equivalent. Solution Convert the integral and the fractional parts separately then add them up. For the fractional part, proceed as follows: Multiply the fractional part by 2 and note down the product Take the fractional part of the immediate product and multiply it by 2 again. Continue this process until the fractional part of the subsequent product is 0 or starts to repeat itself. The following examples illustrate how to convert hexadecimal number to a decimal numberExample Convert octal number 8 to its binary equivalent Solution Working from left to the right, each octal number is represented using three digits and then combined we get the final binary equivalent.

Converting hexadecimal numbers to decimal number To convert hexadecimal number to base 10 equivalent we proceed as follows: However, it is important to note that the maximum absolute value of a octal digit is 7. For example Is not a valid octal number because digit 9 is not an octal digit, but 8 is valid because all the digits are in the range Example shows how to convert an octal number to a decimal number.