Top Banner

of 120

Philippine Income Taxation

Mar 01, 2016

Download

Documents

Cha

Individual taxation in the philippines
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • INTRODUCTION TOCOMPUTING

    AMA CS101

    CHARLENE R. FRANCISCOSTUDENT # 031307

    Assignment No. 1Computer Number System and Digital Logic Design

  • 1Number Systems, Base Conversions, and Computer DataRepresentation

    Decimal and Binary NumbersWhen we write decimal (base 10) numbers, we use a positional notation system. Each digit is multipliedby an appropriate power of 10 depending on its position in the number:

    For example:843 = 8 x 102 + 4 x 101 + 3 x 100

    = 8 x 100 + 4 x 10 + 3 x 1= 800 + 40 + 3

    For whole numbers, the rightmost digit position is the ones position (100 = 1). The numeral in that positionindicates how many ones are present in the number. The next position to the left is tens, then hundreds,thousands, and so on. Each digit position has a weight that is ten times the weight of the position to its right.

    In the decimal number system, there are ten possible values that can appear in each digit position, andso there are ten numerals required to represent the quantity in each digit position. The decimal numeralsare the familiar zero through nine (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

    In a positional notation system, the number base is called the radix. Thus, the base ten system that wenormally use has a radix of 10. The term radix and base can be used interchangeably. When writingnumbers in a radix other than ten, or where the radix isnt clear from the context, it is customary to specifythe radix using a subscript. Thus, in a case where the radix isnt understood, decimal numbers would bewritten like this:

    12710 1110 567310

    Generally, the radix will be understood from the context and the radix specification is left off. The binary

    number system is also a positional notation numbering system, but in this case, thebase is not ten, but is instead two. Each digit position in a binary number represents a power oftwo. So, when we write a binary number, each binary digit is multiplied by an appropriate power of 2based on the position in the number:

    For example:101101 = 1 x 25 + 0 x 24 + 1 x 23 + 1 x 22 + 0 x 21 + 1 x 20

    = 1 x 32 + 0 x 16 + 1 x 8 + 1 x 4 + 0 x 2 + 1 x 1= 32 + 8 + 4 + 1

    In the binary number system, there are only two possible values that can appear in each digit position ratherthan the ten that can appear in a decimal number. Only the numerals 0 and 1 are used in binary numbers.The term bit is a contraction of the words binary and digit, and when talking about binary numbers theterms bit and digit can be used interchangeably. When talking about binary numbers, it is often necessary totalk of the number of bits used to store or represent the number. This merely describes the number of binarydigits that would be required to write the number. The number in the above example is a 6 bit number.

    The following are some additional examples of binary numbers:1011012 112 101102

  • Conversion between Decimal and BinaryConverting a number from binary to decimal is quite easy. All that is required is to find thedecimal value of each binary digit position containing a 1 and add them up.

    For example: convert 101102 to decimal.

    1 0 1 1 0 1 x 21 = 2 1 x 22 = 4 1 x 24 = 16

    22

    Another example: convert 110112 to decimal

    1 1 0 1 1 1 x 20 = 1 1 x 21 = 2 1 x 23 = 8 1 x 24 = 16

    27

    The method for converting a decimal number to binary is one that can be used to convert fromdecimal to any number base. It involves using successive division by the radix until the dividendreaches 0. At each division, the remainder provides a digit of the converted number, starting withthe least significant digit.

    An example of the process: convert 3710 to binary

    37 / 2 = 18 remainder 1 (least significant digit)18 / 2 = 9 remainder 09 / 2 = 4 remainder 14 / 2 = 2 remainder 02 / 2 = 1 remainder 01 / 2 = 0 remainder 1 (most significant digit)

    The resulting binary number is: 100101

    Another example: convert 9310 to binary

    93 / 2 = 46 remainder 1 (least significant digit)46 / 2 = 23 remainder 023 / 2 = 11 remainder 111 / 2 = 5 remainder 15 / 2 = 2 remainder 12 / 2 = 1 remainder 01 / 2 = 0 remainder 1 (most significant digit)

    The resulting binary number is: 1011101

    Hexadecimal NumbersIn addition to binary, another number base that is commonly used in digital systems is base 16.This number system is called hexadecimal, and each digit position represents a power of 16. Forany number base greater than ten, a problem occurs because there are more than ten symbolsneeded to represent the numerals for that number base. It is customary in these cases to use the

  • ten decimal numerals followed by the letters of the alphabet beginning with A to provide theneeded numerals. Since the hexadecimal system is base 16, there are sixteen numeralsrequired. The following are the hexadecimal numerals:

    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

    The following are some examples of hexadecimal numbers:

    1016 4716 3FA16 A03F16

    The reason for the common use of hexadecimal numbers is the relationship between the numbers2 and 16. Sixteen is a power of 2 (16 = 24). Because of this relationship, four digits in a binarynumber can be represented with a single hexadecimal digit. This makes conversion betweenbinary and hexadecimal numbers very easy, and hexadecimal can be used to write largebinary numbers with much fewer digits. When working with large digital systems, such ascomputers, it is common to find binary numbers with 8, 16 and even 32 digits. Writing a 16 or 32bit binary number would be quite tedious and error prone. By using hexadecimal, the numberscan be written with fewer digits and much less likelihood of error.

    To convert a binary number to hexadecimal, divide it into groups of four digits starting with therightmost digit. If the number of digits isnt a multiple of 4, prefix the number with 0s so that eachgroup contains 4 digits. For each four digit group, convert the 4 bit binary number into anequivalent hexadecimal digit. (See the Binary, BCD, and Hexadecimal Number Tables at the endof this document for the correspondence between 4 bit binary patterns and hexadecimal digits)

    For example: Convert the binary number 10110101 to a hexadecimal number

    Divide into groups for 4 digits 1011 0101Convert each group to hex digit B 5

    B516

    Another example: Convert the binary number 0110101110001100 to hexadecimal

    Divide into groups of 4 digits 0110 1011 1000 1100Convert each group to hex digit 6 B 8 C

    6B8C16

    To convert a hexadecimal number to a binary number, convert each hexadecimal digit into agroup of 4 binary digits.

    Example: Convert the hex number 374F into binary

    3 7 4 FConvert the hex digits to binary 0011 0111 0100 1111

    00110111010011112

    There are several ways in common use to specify that a given number is in hexadecimalrepresentation rather than some other radix. In cases where the context makes it absolutely clearthat numbers are represented in hexadecimal, no indicator is used. In much written materialwhere the context doesnt make it clear what the radix is, the numeric subscript 16 following thehexadecimal number is used. In most programming languages, this method isnt really feasible,so there are several conventions used depending on the language. In the C and C++ languages,hexadecimal constants are represented with a 0x preceding the number, as in: 0x317F, or0x1234, or 0xAF. In assembler programming languages that follow the Intel style, a hexadecimalconstant begins with a numeric character (so that the assembler can distinguish it from a variable

  • name), a leading 0 being used if necessary. The letter h is then suffixed onto the number toinform the assembler that it is a hexadecimal constant. In Intel style assembler format: 371Fh and0FABCh are valid hexadecimal constants. Note that: A37h isnt a valid hexadecimal constant. Itdoesnt begin with a numeric character, and so will be taken by the assembler as a variablename. In assembler programming languages that follow the Motorola style, hexadecimalconstants begin with a $ character. So in this case: $371F or $FABC or $01 are validhexadecimal constants.

    Binary Coded Decimal NumbersAnother number system that is encountered occasionally is Binary Coded Decimal. In thissystem, numbers are represented in a decimal form, however each decimal digit is encodedusing a four bit binary number.

    For example: The decimal number 136 would be represented in BCD as follows:

    136 = 0001 0011 01101 3 6

    Conversion of numbers between decimal and BCD is quite simple. To convert from decimal toBCD, simply write down the four bit binary pattern for each decimal digit. To convert from BCD todecimal, divide the number into groups of 4 bits and write down the corresponding decimal digitfor each 4 bit group.

    There are a couple of variations on the BCD representation, namely packed and unpacked. Anunpacked BCD number has only a single decimal digit stored in each data byte. In this case, thedecimal digit will be in the low four bits and the upper 4 bits of the byte will be 0. In the packedBCD representation, two decimal digits are placed in each byte. Generally, the high order bits ofthe data byte contain the more significant decimal digit.

    An example: The following is a 16 bit number encoded in packed BCD format:01010110 10010011

    This is converted to a decimal number as follows:0101 0110 1001 0011

    5 6 9 3The value is 5693 decimal

    Another example: The same number in unpacked BCD (requires 32 bits)00000101 00000110 00001001 00000011

    5 6 9 3

    The use of BCD to represent numbers isnt as common as binary in most computer systems, as itis not as space efficient. In packed BCD, only 10 of the 16 possible bit patterns in each 4 bit unitare used. In unpacked BCD, only 10 of the 256 possible bit patterns in each byte are used. A 16bit quantity can represent the range 0-65535 in binary, 0-9999 in packed BCD and only 0-99 inunpacked BCD.

    Fixed Precision and Overflow.So far, in talking about binary numbers, we havent considered the maximum size of the number.We have assumed that as many bits are available as needed to represent the number. In mostcomputer systems, this isnt the case. Numbers in computers are typically represented using afixed number of bits. These sizes are typically 8 bits, 16 bits, 32 bits, 64 bits and 80 bits. Thesesizes are generally a multiple of 8, as most computer memories are organized on an 8 bit bytebasis. Numbers in which a specific number of bits are used to represent the value are called fixedprecision numbers. When a specific number of bits are used to represent a number, thatdetermines the range of possible values that can be represented. For example, there are 256

  • possible combinations of 8 bits, therefore an 8 bit number can represent 256 distinct numericvalues and the range is typically considered to be 0-255. Any number larger than 255 cant berepresented using 8 bits. Similarly, 16 bits allows a range of 0-65535.

    When fixed precision numbers are used, (as they are in virtually all computer calculations) theconcept of overflow must be considered. An overflow occurs when the result of a calculation cantbe represented with the number of bits available. For example when adding the two eight bitquantities: 150 + 170, the result is 320. This is outside the range 0-255, and so the result cant berepresented using 8 bits. The result has overflowed the available range. When overflow occurs,the low order bits of the result will remain valid, but the high order bits will be lost. This results in avalue that is significantly smaller than the correct result.

    When doing fixed precision arithmetic (which all computer arithmetic involves) it is necessary tobe conscious of the possibility of overflow in the calculations.

    Signed and Unsigned Numbers.So far, we have only considered positive values for binary numbers. When a fixed precisionbinary number is used to hold only positive values, it is said to be unsigned. In this case, therange of positive values that can be represented is 0 -- 2n-1, where n is the number of bits used. Itis also possible to represent signed (negative as well as positive) numbers in binary. In this case,part of the total range of values is used to represent positive values, and the rest of the range isused to represent negative values.

    There are several ways that signed numbers can be represented in binary, but the most commonrepresentation used today is called twos complement. The term twos complement is somewhatambiguous, in that it is used in two different ways. First, as a representation, twos complement isa way of interpreting and assigning meaning to a bit pattern contained in a fixed precision binaryquantity. Second, the term twos complement is also used to refer to an operation that can beperformed on the bits of a binary quantity. As an operation, the twos complement of a number isformed by inverting all of the bits and adding 1. In a binary number being interpreted using thetwos complement representation, the high order bit of the number indicates the sign. If the signbit is 0, the number is positive, and if the sign bit is 1, the number is negative. For positivenumbers, the rest of the bits hold the true magnitude of the number. For negative numbers, thelower order bits hold the complement (or bitwise inverse) of the magnitude of the number. It isimportant to note that twos complement representation can only be applied to fixed precisionquantities, that is, quantities where there are a set number of bits.

    Twos complement representation is used because it reduces the complexity of the hardware inthe arithmetic-logic unit of a computers CPU. Using a twos complement representation, all of thearithmetic operations can be performed by the same hardware whether the numbers areconsidered to be unsigned or signed. The bit operations performed are identical, the differencecomes from the interpretation of the bits. The interpretation of the value will be differentdepending on whether the value is considered to be unsigned or signed.

    For example: Find the 2s complement of the following 8 bit number00101001

    11010110 First, invert the bits+ 00000001 Then, add 1= 11010111

    The 2s complement of 00101001 is 11010111

  • Another example: Find the 2s complement of the following 8 bit number10110101

    01001010 Invert the bits+ 00000001 then add 1= 01001011

    The 2s complement of 10110101 is 01001011

    The counting sequence for an eight bit binary value using 2s complement representation appearsas follows:

    01111111 7Fh 127 largest magnitude positive number01111110 7Eh 12601111101 7Dh 12500000011 03h00000010 02h00000001 01h00000000 00h11111111 0FFh -111111110 0FEh -211111101 0FDh -310000010 82h -12610000001 81h -12710000000 80h -128 largest magnitude negative number

    Notice in the above sequence that counting up from 0, when 127 is reached, the next binarypattern in the sequence corresponds to -128. The values jump from the greatest positive numberto the greatest negative number, but that the sequence is as expected after that. (i.e. adding 1 to128 yields 127, and so on.). When the count has progressed to 0FFh (or the largest unsignedmagnitude possible) the count wraps around to 0. (i.e. adding 1 to 1 yields 0).

    ASCII Character EncodingThe name ASCII is an acronym for: American Standard Code for Information Interchange. It is acharacter encoding standard developed several decades ago to provide a standard way for digitalmachines to encode characters. The ASCII code provides a mechanism for encoding alphabeticcharacters, numeric digits, and punctuation marks for use in representing text and numberswritten using the Roman alphabet. As originally designed, it was a seven bit code. The seven bitsallow the representation of 128 unique characters. All of the alphabet, numeric digits andstandard English punctuation marks are encoded. The ASCII standard was later extended to aneight bit code (which allows 256 unique code patterns) and various additional symbols wereadded, including characters with diacritical marks (such as accents) used in European languages,which dont appear in English. There are also numerous non-standard extensions to ASCII givingdifferent encoding for the upper 128 character codes than the standard. For example, Thecharacter set encoded into the display card for the original IBM PC had a non-standard encodingfor the upper character set. This is a non-standard extension that is in very wide spread use, andcould be considered a standard in itself.

    Some important things to note about ASCII code:1) The numeric digits, 0-9, are encoded in sequence starting at 30h2) The upper case alphabetic characters are sequential beginning at 41h3) The lower case alphabetic characters are sequential beginning at 61h

  • 4) The first 32 characters (codes 0-1Fh) and 7Fh are control characters. They do not have astandard symbol (glyph) associated with them. They are used for carriage control, andprotocol purposes. They include 0Dh (CR or carriage return), 0Ah (LF or line feed), 0Ch(FF or form feed), 08h (BS or backspace).

    5) Most keyboards generate the control characters by holding down a control key (CTRL)and simultaneously pressing an alphabetic character key. The control code will have thesame value as the lower five bits of the alphabetic key pressed. So, for example, thecontrol character 0Dh is carriage return. It can be generated by pressing CTRL-M. To getthe full 32 control characters a few at the upper end of the range are generated bypressing CTRL and a punctuation key in combination. For example, the ESC (escape)character is generated by pressing CTRL-[ (left square bracket).

    Conversions Between Upper and Lower Case ASCII Letters.Notice on the ASCII code chart that the uppercase letters start at 41h and that the lower caseletters begin at 61h. In each case, the rest of the letters are consecutive and in alphabetic order.The difference between 41h and 61h is 20h. Therefore the conversion between upper and lowercase involves either adding or subtracting 20h to the character code. To convert a lower caseletter to upper case, subtract 20h, and conversely to convert upper case to lower case, add 20h.It is important to note that you need to first ensure that you do in fact have an alphabeticcharacter before performing the addition or subtraction. Ordinarily, a check should be made thatthe character is in the range 41h5Ah for upper case or 61h-7Ah for lower case.

    Conversion Between ASCII and BCD.Notice also on the ASCII code chart that the numeric characters are in the range 30h-39h.Conversion between an ASCII encoded digit and an unpacked BCD digit can be accomplished byadding or subtracting 30h. Subtract 30h from an ASCII digit to get BCD, or add 30h to a BCD digitto get ASCII. Again, as with upper and lower case conversion for alphabetic characters, it isnecessary to ensure that the character is in fact a numeric digit before performing the subtraction.The digit characters are in the range 30h-39h.

  • Binary, BCD and Hexadecimal Number Tables

    Powers of 2:20 ......................121 ......................222 ......................423 ......................824 .................... 1625 .................... 3226 .................... 6427 .................. 12828 .................. 25629 .................. 512

    210 ................ 1024211 ................ 2048212 ................ 4096213 ................ 8192214 .............. 16384215 .............. 32768216 .............. 65536

    Hexadecimal Digits0 ......................0 00001 ......................1 00012 ......................2 00103 ......................3 00114 ......................4 01005 ......................5 01016 ......................6 01107 ......................7 01118 ......................8 10009 ......................9 1001

    10 ..................... A 101011 ..................... B 101112 ..................... C 110013 ..................... D 110114 ..................... E 111015 ......................F 1111

    BCD Digits

    0 ................ 00001 ................ 00012 ................ 00103 ................ 00114 ................ 01005 ................ 01016 ................ 01107 ................ 01118 ................ 10009 ................ 1001

  • 0 00000000 001 00000001 012 00000010 023 00000011 034 00000100 045 00000101 056 00000110 067 00000111 078 00001000 089 00001001 09

    10 00001010 0A11 00001011 0B12 00001100 0C13 00001101 0D14 00001110 0E15 00001111 0F16 00010000 1017 00010001 1131 00011111 1F32 00100000 2063 00111111 3F64 01000000 4065 01000001 41

    127 01111111 7F128 10000000 80129 10000001 81255 11111111 FF256 0000000100000000 0100

    32767 0111111111111111 7FFF32768 1000000000000000 800065535 1111111111111111 FFFF

    Equivalent Numbers in Decimal, Binary and Hexadecimal Notation:Decimal Binary Hexadecimal

  • 1ASCII Character Set

    Low OrderBits

    High Order Bits0000 0001 0010 0011 0100 0101 0110 0111

    0 1 2 3 4 5 6 70000 00001 10010 20011 30100 40101 50110 60111 71000 81001 91010 A1011 B1100 C1101 D1110 E1111 F

    NUL DLE Space 0 @ P ` pSOH DC1 ! 1 A Q a qSTX DC2 2 B R b rETX DC3 # 3 C S c sEOT DC4 $ 4 D T d tENQ NAK % 5 E U e uACK SYN & 6 F V f vBEL ETB 7 G W g wBS CAN ( 8 H X h xHT EM ) 9 I Y i yLF SUB * : J Z j zVT ESC + ; K [ k{ FF FS , < L l| CR GS - = M ]m } SO RS . > N ^n ~ SI US / ? O _o DEL

    Digital Logic DesignIntroductionA digital computer stores data in terms of digits (numbers) and proceeds in discrete steps from one state to the next.The states of a digital computer typically involve binary digits which may take the form of the presence or absence ofmagnetic markers in a storage medium , on-off switches or relays. In digital computers, even letters, words and wholetexts are represented digitally.

    Digital Logic is the basis of electronic systems, such as computers and cell phones. Digital Logic is rooted inbinary code, a series of zeroes and ones each having an opposite value. This system facilitates the design ofelectronic circuits that convey information, including logic gates. Digital Logic gate functions include and, orand not. The value system translates input signals into specific output. Digital Logic facilitates computing,robotics and other electronic applications.

    Digital Logic Design is foundational to the fields of electrical engineering and computer engineering. DigitalLogic designers build complex electronic components that use both electrical and computationalcharacteristics. These characteristics may involve power, current, logical function, protocol and user input.Digital Logic Design is used to develop hardware, such as circuit boards and microchip processors. Thishardware processes user input, system protocol and other data in computers, navigational systems, cell phonesor other high-tech systems.

  • 2Data Representationand Number systemNumeric systemsThe numeric system we use daily is the decimal system, but this system is not convenient for machines since theinformation is handled codified in the shape of on or off bits; this way of codifying takes us to the necessity of knowingthe positional calculation which will allow us to express a number in any base where we need it.

    Radix number systems

    The numeric system we use daily is the decimal system, but this system is not convenient for machines since theinformation is handled codified in the shape of on or off bits; this way of codifying takes us to the necessity of knowingthe positional calculation which will allow us to express a number in any base where we need it.

    A base of a number system or radix defines the range of values that a digit may have.

    In the binary system or base 2, there can be only two values for each digit of a number, either a "0" or a "1".

    In the octal system or base 8, there can be eight choices for each digit of a number:

    "0", "1", "2", "3", "4", "5", "6", "7".

    In the decimal system or base 10, there are ten different values for each digit of a number:

    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9".

    In the hexadecimal system, we allow 16 values for each digit of a number:

    "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", and "F".

    Where A stands for 10, B for 11 and so on.

    Conversion among radices

    - Convert from Decimal to Any Base

    Lets think about what you do to obtain each digit. As an example, let's start with a decimal number 1234 and convert itto decimal notation. To extract the last digit, you move the decimal point left by one digit, which means that you dividethe given number by its base 10.

    1234/10 = 123 + 4/10

    The remainder of 4 is the last digit. To extract the next last digit, you again move the decimal point left by one digit andsee what drops out.

    123/10 = 12 + 3/10

    The remainder of 3 is the next last digit. You repeat this process until there is nothing left. Then you stop. In summary,you do the following:

  • 3Quotient Remainder

    -----------------------------

    1234/10 = 123 4 --------+------+ |----+ | |

    123/10 = 12 312/10 = 1 21/10 = 0 1 --+ | | |(Stop when the quotient is 0)

    | | | |1 2 3 4 (Base 10)

    Now, let's try a nontrivial example. Let's express a decimal number 1341 in binary notation. Note that the desired base is2, so we repeatedly divide the given decimal number by 2.

    Quotient Remainder-----------------------------

    1341/2 = 670 1 ----------------------+670/2 = 335 0 --------------------+ |335/2 = 167 1 ------------------+ | |167/2 = 83 1 ----------------+ | | |83/2 = 41 1 --------------+ | | | |41/2 = 20 1 ------------+ | | | | |20/2 = 10 0 ----------+ | | | | | |10/2 = 5 0 --------+ | | | | | | |5/2 = 2 1 ------+ | | | | | | | |2/2 = 1 0 ----+ | | | | | | | | |1/2 = 0 1 --+ | | | | | | | | | |(Stop when the

    | | | | | | | | | | | quotient is 0)1 0 1 0 0 1 1 1 1 0 1 (BIN; Base 2)

    Let's express the same decimal number 1341 in octal notation.Quotient Remainder

    -----------------------------

    1341/8 = 167 5 --------+167/8 = 20 7 ------+ |20/8 = 2 4 ----+ | |2/8 = 0 2 --+ | | | (Stop when the quotient is 0)

    | | | |2 4 7 5 (OCT; Base 8)

    Let's express the same decimal number 1341 in hexadecimal notation.Quotient Remainder

    -----------------------------

    1341/16 = 83 13 ------+----+ |83/16 = 5 3

    5/16 = 0 5 --+ | | (Stop when the quotient is 0)| | |5 3 D (HEX; Base 16)

    In conclusion, the easiest way to convert fixed point numbers to any base is to convert each part separately. We begin byseparating the number into its integer and fractional part. The integer part is converted using the remainder method, byusing a successive division of the number by the base until a zero is obtained. At each division, the reminder is kept andthen the new number in the base r is obtained by reading the remainder from the lat remainder upwards.

    The conversion of the fractional part can be obtained by successively multiplying the fraction with the base. If we iteratethis process on the remaining fraction, then we will obtain successive significant digit. This methods form the basis ofthe multiplication methods of converting fractions between bases

    Example. Convert the decimal number 3315 to hexadecimal notation. What about the hexadecimal equivalent of the

  • 4decimal number 3315.3?

  • 5(HEX; Base 16)Product Integer Part 0.4 C C C ...

    -------

    0.3*16---

    =

    --------

    4.8-------------

    4|

    ----+

    ||

    ||

    || | |

    0.8*16 = 12.8 12 ------+ | | | |0.8*16 = 12.8 12 --------+ | | |

    n1

    d iib

    Solution:Quotient Remainder

    -----------------------------

    3315/16 = 207 3 ------+207/16 = 12 15 ----+ |12/16 = 0 12 --+ | | (Stop when the quotient is 0)

    | | |C F 3 (HEX; Base 16)

    -

    0.8*16 = 12.8 12 ----------+ | |: ---------------------+

    :

    Thus, 3315.3 (DEC) --> CF3.4CCC... (HEX)

    - Convert From Any Base to Decimal

    Let's think more carefully what a decimal number means. For example, 1234 means that there are four boxes (digits);and there are 4 one's in the right-most box (least significant digit), 3 ten's in the next box, 2 hundred's in the next box,and finally 1 thousand's in the left-most box (most significant digit). The total is 1234:

    Original Number: 1 2 3 4| | | |

    How Many Tokens: 1 2 3 4Digit/Token Value: 1000 100 10 1Value: 1000 + 200 + 30 + 4 = 1234

    or simply, 1*1000 + 2*100 + 3*10 + 4*1 = 1234

    Thus, each digit has a value: 10^0=1 for the least significant digit, increasing to 10^1=10, 10^2=100, 10^3=1000, and soforth.

    Likewise, the least significant digit in a hexadecimal number has a value of 16^0=1 for the least significant digit,increasing to 16^1=16 for the next digit, 16^2=256 for the next, 16^3=4096 for the next, and so forth. Thus, 1234 meansthat there are four boxes (digits); and there are 4 one's in the right-most box (least significant digit), 3 sixteen's in thenext box, 2 256's in the next, and 1 4096's in the left-most box (most significant digit). The total is:

    1*4096 + 2*256 + 3*16 + 4*1 = 4660

    In summary, the conversion from any base to base 10 can be obtained from the formulae

    1 0 = ix Where b is the base, d the digit at position i, m the number of digit after the decimal point, n the numberi=m

    of digits of the integer part and X10 is the obtained number in decimal. This form the basic of the polynomial method ofconverting numbers from any base to decimal

    Example. Convert 234.14 expressed in an octal notation to decimal.

    2*82 + 3*81 + 4*80+1*8-1 + 4*8-2 = 2*64 +3*8 +4*1 +1/8 +4/64 =156.1875

  • 6Original Number: 4 B 3 . 3| | | |

    How Many Tokens: 4 11 3 3Digit/Token Value: 2 6 16 1 0.0625Value: 10 4 +176 + 3 + 0.1875 = 1203.1875

    Example. Convert the hexadecimal number 4B3 to decimal notation. What about the decimal equivalent of thehexadecimal number 4B3.3?

    Solution:

    52

    Example. Convert 234.14 expressed in an octal notation to decimal.

    Solution:

    Original Number: 2 3 4 . 1 4| | | | |

    How Many Tokens: 2 3 4 1 4Digit/Token Value: 64 8 1 0.125 0.015625Value: 128 + 24 + 4 + 0.125 + 0.0625 = 156.1875

    - Relationship between Binary - Octal and Binary-hexadecimal

    As demonstrated by the table bellow, there is a direct correspondence between the binary system and the octal system,with three binary digits corresponding to one octal digit. Likewise, four binary digits translate directly into onehexadecimal digit.

    BIN OCT HEX DEC----------------------

    0000 00 0 00001 01 1 10010 02 2 20011 03 3 30100 04 4 40101 05 5 50110 06 6 60111 07 7 7----------------------

    1000 10 8 81001 11 9 91010 12 A 101011 13 B 111100 14 C 121101 15 D 131110 16 E 141111 17 F 15

    With such relationship, In order to convert a binary number to octal, we partition the base 2 number into groups of threestarting from the radix point, and pad the outermost groups with 0s as needed to form triples. Then, we convert eachtriple to the octal equivalent.

    For conversion from base 2 to base 16, we use groups of four.

    Consider converting 101102 to base 8:

    101102 = 0102 1102 = 28 68 = 268

  • 7Notice that the leftmost two bits are padded with a 0 on the left in order to create a full triplet.

  • 8Now consider converting 101101102 to base 16:

    101101102 = 10112 01102 = B16 616 = B616

    (Note that B is a base 16 digit corresponding to 1110. B is not a variable.)

    The conversion methods can be used to convert a number from any base to any other base, but it may not be veryintuitive to convert something like 513.03 to base 7. As an aid in performing an unnatural conversion, we can convert tothe more familiar base 10 form as an intermediate step, and then continue the conversion from base 10 to the target base.As a general rule, we use the polynomial method when converting into base 10, and we use the remainder andmultiplication methods when converting out of base 10.

    Numeric complements

    The radix complement of an n digit number y in radix b is, by definition, bn y. Adding this to x results in the value x +bn y or x y + bn. Assuming y x, the result will always be greater than bn and dropping the initial '1' is the same assubtracting bn, making the result x y + bn bn or just x y, the desired result.

    The radix complement is most easily obtained by adding 1 to the diminished radix complement, which is (bn 1) y.Since (bn 1) is the digit b 1 repeated n times (because bn 1 = bn 1n = (b 1)(bn 1 + bn 2 + ... + b + 1) = (b 1)bn 1 + ... + (b 1), see also binomial numbers), the diminished radix complement of a number is found by complementingeach digit with respect to b 1 (that is, subtracting each digit in y from b 1). Adding 1 to obtain the radix complementcan be done separately, but is most often combined with the addition of x and the complement of y.

    In the decimal numbering system, the radix complement is called the ten's complement and the diminished radixcomplement the nines' complement.

    In binary, the radix complement is called the two's complement and the diminished radix complement the ones'complement. The naming of complements in other bases is similar.

    - Decimal example

    To subtract a decimal number y from another number x using the method of complements, the ten's complement of y(nines' complement plus 1) is added to x. Typically, the nines' complement of y is first obtained by determining thecomplement of each digit. The complement of a decimal digit in the nines' complement system is the number that mustbe added to it to produce 9. The complement of 3 is 6, the complement of 7 is 2, and so on. Given a subtractionproblem:

    873 (x)- 218 (y)The nines' complement of y (218) is 781. In this case, because y is three digits long, this is the same as subtracting yfrom 999. (The number of 9's is equal to the number of digits of y.)

    Next, the sum of x, the nines' complement of y, and 1 is taken:

    873 (x)+ 781 (complement of y)+ 1 (to get the ten's complement of y)=====

    1655

    The first "1" digit is then dropped, giving 655, the correct answer.

    If the subtrahend has fewer digits than the minuend, leading zeros must be added which will become leading nines whenthe nines' complement is taken. For example:

  • 948032 (x)- 391 (y)becomes the sum:48032 (x)

    + 99608 (nines' complement of y)+ 1 (to get the ten's complement)=======

    147641Dropping the "1" gives the answer: 47641

    - Binary example

    The method of complements is especially useful in binary (radix 2) since the ones' complement is very easily obtainedby inverting each bit (changing '0' to '1' and vice versa). And adding 1 to get the two's complement can be done bysimulating a carry into the least significant bit. For example:

    01100100 (x, equals decimal 100)- 00010110 (y, equals decimal 22)

    becomes the sum:01100100 (x)

    + 11101001 (ones' complement of y)+ 1 (to get the two's complement)==========

    101001110

    Dropping the initial "1" gives the answer: 01001110 (equals decimal 78)

    Signed fixed point numbers

    Up to this point we have considered only the representation of unsigned fixed point numbers. The situation is quitedifferent in representing signed fixed point numbers. There are four different ways of representing signed numbers thatare commonly used: sign-magnitude, ones complement, twos complement, and excess notation. We will cover each inturn, using integers for our examples. The Table below shows for a 3-bit number how the various representationsappear.

    Decimal Unsigned SignMag. 1s Comp. 2s Comp. Excess 47 111 6 110 5 101 4 100 3 011 011 011 011 1112 010 010 010 010 1101 001 001 001 001 101+0 000 000 000 000 100-0 100 111 000 100-1 101 110 111 011-2 110 101 110 010-3 111 100 101 001-4 100 000

  • 10

    Table1. 3 bit number representation

  • 11

    - Signed Magnitude Representation

    The signed magnitude (also referred to as sign and magnitude) representation is most familiar to us as the base 10number system. A plus or minus sign to the left of a number indicates whether the number is positive or negative as in+1210 or 1210. In the binary signed magnitude representation, the leftmost bit is used for the sign, which takes on avalue of 0 or 1 for + or , respectively. The remaining bits contain the absolute magnitude.

    Consider representing (+12)10 and (12)10 in an eight-bit format:

    (+12)10 = (00001100)2

    (12)10 = (10001100)2

    The negative number is formed by simply changing the sign bit in the positive number from 0 to 1. Notice that there areboth positive and negative representations for zero: +0= 00000000 and -0= 10000000.

    - Ones Complement Representation

    The ones complement operation is trivial to perform: convert all of the 1s in the number to 0s, and all of the 0s to 1s.See the fourth column in Table1 for examples. We can observe from the table that in the ones complementrepresentation the leftmost bit is 0 for positive numbers and 1 for negative numbers, as it is for the signed magnituderepresentation. This negation, changing 1s to 0s and changing 0s to 1s, is known as complementing the bits.Consider again representing (+12)10 and (12)10 in an eight-bit format, now using the ones complementrepresentation:

    (+12)10 = (00001100)2

    (12)10 = (11110011)2

    Note again that there are representations for both +0 and 0, which are 00000000 and 11111111, respectively. As aresult, there are only 28 1 = 255 different numbers that can be represented even though there are 28 different bitpatterns.

    The ones complement representation is not commonly used. This is at least partly due to the difficulty in makingcomparisons when there are two representations for 0. There is also additional complexity involved in adding numbers.

    - Twos Complement Representation

    The twos complement is formed in a way similar to forming the ones complement: complement all of the bits in thenumber, but then add 1, and if that addition results in a carry-out from the most significant bit of the number, discard thecarry-out.

    Examination of the fifth column of Table above shows that in the twos complement representation, the leftmost bit isagain 0 for positive numbers and is 1 for negative numbers. However, this number format does not have the unfortunatecharacteristic of signed-magnitude and ones complement representations: it has only one representation for zero. To seethat this is true, consider forming the negative of (+0)10, which has the bit pattern: (+0)10 = (00000000)2

    Forming the ones complement of (00000000)2 produces (11111111)2 and adding

    1 to it yields (00000000)2, thus (0)10 = (00000000)2. The carry out of the leftmost position is discarded in twoscomplement addition (except when detecting an overflow condition). Since there is only one representation for 0, andsince all bit patterns are valid, there are 28 = 256 different numbers that can be represented.

    Consider again representing (+12)10 and (12)10 in an eight-bit format, this time using the twos complementrepresentation. Starting with (+12)10 =(00001100)2, complement, or negate the number, producing (11110011)2.

  • 12

    Now add 1, producing (11110100)2, and thus (12)10 = (11110100)2:

    (+12)10 = (00001100)2

    (12)10 = (11110100)2

    There is an equal number of positive and negative numbers provided zero is considered to be a positive number, whichis reasonable because its sign bit is 0. The positive numbers start at 0, but the negative numbers start at 1, and so themagnitude of the most negative number is one greater than the magnitude of the most positive number. The positivenumber with the largest magnitude is +127, and the negative number with the largest magnitude is 128. There is thusno positive number that can be represented that corresponds to the negative of 128. If we try to form the twoscomplement negative of 128, then we will arrive at a negative number, as shown below:

    (128)10 = (10000000)2(128)10 = (01111111(128)10 + (+0000001)2(128)10 )2(128)10 = (10000000)2

    The twos complement representation is the representation most commonly used in conventional computers.

    - Excess Representation

    In the excess or biased representation, the number is treated as unsigned, but is shifted in value by subtracting the biasfrom it. The concept is to assign the smallest numerical bit pattern, all zeros, to the negative of the bias, and assign theremaining numbers in sequence as the bit patterns increase in magnitude. A convenient way to think of an excessrepresentation is that a number is represented as the sum of its twos complement form and another number, which isknown as the excess, or bias. Once again, refer to Table 2.1, the rightmost column, for examples.

    Consider again representing (+12)10 and (12)10 in an eight-bit format but now using an excess 128 representation. Anexcess 128 number is formed by adding 128 to the original number, and then creating the unsigned binary version. For(+12)10, we compute (128 + 12 = 140)10 and produce the bit pattern (10001100)2. For (12)10, we compute (128 + 12 =116)10 and produce the bit pattern (01110100)2

    (+12)10 = (10001100)2

    (12)10 = (01110100)2

    Note that there is no numerical significance to the excess value: it simply has the effect of shifting the representation ofthe twos complement numbers.

    There is only one excess representation for 0, since the excess representation is simply a shifted version of the twoscomplement representation. For the previous case, the excess value is chosen to have the same bit pattern as the largestnegative number, which has the effect of making the numbers appear in numerically sorted order if the numbers areviewed in an unsigned binary representation.

    Thus, the most negative number is (128)10 = (00000000)2 and the most positive number is (+127)10 = (11111111)2.This representation simplifies making comparisons between numbers, since the bit patterns for negative numbers havenumerically smaller values than the bit patterns for positive numbers. This is important for representing the exponents offloating point numbers, in which exponents of two numbers are compared in order to make them equal for addition andsubtraction.

    choosing a bias:

    The bias chosen is most often based on the number of bits (n) available for representing an integer. To get anapproximate equal distribution of true values above and below 0, the bias should be 2(n-1) or 2(n-1) - 1

  • Floating point representation

    Floating point is a numerical representation system in which a string of digits represent a real number. The namefloating point refers to the fact that the radix point (decimal point or more commonly in computers, binary point) can beplaced anywhere relative to the digits within the string. A fixed point is of the form a bn where a is the fixed point partoften referred to as the mantissa, or significand of the number b represents the base and n the exponent. Thus a floatingpoint number can be characterized by a triple of numbers: sign, exponent, and significand.

    - Normalization

    A potential problem with representing floating point numbers is that the same number can be represented in differentways, which makes comparisons and arithmetic operations difficult. For example, consider the numerically equivalentforms shown below:

    3584.1 100 = 3.5841 103 = .35841 104.

    In order to avoid multiple representations for the same number, floating point numbers are maintained in normalizedform. That is, the radix point is shifted to the left or to the right and the exponent is adjusted accordingly until the radixpoint is to the left of the leftmost nonzero digit. So the rightmost number above is the normalized one. Unfortunately,the number zero cannot be represented in this scheme, so to represent zero an exception is made. The exception to thisrule is that zero is represented as all 0s in the mantissa.

    If the mantissa is represented as a binary, that is, base 2, number, and if the normalization condition is that there is aleading 1 in the normalized mantissa, then there is no need to store that 1 and in fact, most floating point formats donot store it. Rather, it is chopped off before packing up the number for storage, and it is restored when unpacking thenumber into exponent and mantissa. This results in having an additional bit of precision on the right of the number, dueto removing the bit on the left. This missing bit is referred to as the hidden bit, also known as a hidden 1.

    For example, if the mantissa in a given format is 1.1010 after normalization, then the bit pattern that is stored is 1010the left-most bit is truncated, or hidden.

    Possible floating point format.

    In order to choose a possible floating point format for a given computer, the programmer must take into considerationthe following:

    The number of words used (i.e. the total number of bits used.)The representation of the mantissa (2s complement etc.)The representation of the exponent (biased etc.)The total number of bits devoted for the mantissa and the exponentThe location of the mantissa (exponent first or mantissa first)

    Because of the five points above, the number of ways in which a floating point number may be represented is legion.Many representation use the format of sign bit to represent a floating point where the leading bit represents the sign

    Sign Exponent Mantissa

    - The IEEE standard for floating point

    The IEEE (Institute of Electrical and Electronics Engineers) has produced a standard for floating point format arithmeticin mini and micro computers.(i.e. ANSI/IEEE 754-1985). This standard specifies how single precision (32 bit) , doubleprecision (64 bit) and Quadruple (128 bit) floating point numbers are to be represented, as well as how arithmetic shouldbe carried out on them.

  • General layout

    The three fields in an IEEE 754 float

    Sign Exponent Fraction

    Binary floating-point numbers are stored in a sign-magnitude form where the most significant bit is the sign bit,exponent is the biased exponent, and "fraction" is the significand without the most significant bit.

    Exponent biasingThe exponent is biased by (2e 1) 1, where e is the number of bits used for the exponent field (e.g. if e=8, then (28 1) 1 = 128 1 = 127 ). Biasing is done because exponents have to be signed values in order to be able to represent bothtiny and huge values, but two's complement, the usual representation for signed values, would make comparison harder.To solve this, the exponent is biased before being stored by adjusting its value to put it within an unsigned rangesuitable for comparison.

    For example, to represent a number which has exponent of 17 in an exponent field 8 bits wide:

    exponentfield = 17 + (28 1) 1 = 17 + 128 1 = 144.

    Single Precision

    The IEEE single precision floating point standard representation requires a 32 bit word, which may be represented asnumbered from 0 to 31, left to right. The first bit is the sign bit, S, the next eight bits are the exponent bits, 'E', and thefinal 23 bits are the fraction 'F':

    S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF0 1 8 9 31

    To convert decimal 17.15 to IEEE Single format:Convert decimal 17 to binary 10001. Convert decimal 0.15 to the repeating binary fraction 0.001001 Combineinteger and fraction to obtain binary 10001.001001 Normalize the binary number to obtain 1.0001001001x24Thus, M =m-1 =0001001001 and E = e+127 = 131 = 10000011.The number is positive, so S=0. Align the values for M, E, and S in the correct fields.0 10000011 00010010011001100110011Note that if the exponent does not use all the field allocated to it, there will be leading 0s while for the mantissa,the zeros will be filled at the end.

    Double Precision

    The IEEE double precision floating point standard representation requires a 64 bit word, which may be represented asnumbered from 0 to 63, left to right. The first bit is the sign bit, S, the next eleven bits are the exponent bits, 'E', and thefinal 52 bits are the fraction 'F':

    S EEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 1 11 12

  • Quad Precision

    The IEEE Quad precision floating point standard representation requires a 128 bit word, which may be represented asnumbered from 0 to 127, left to right. The first bit is the sign bit, S, the next fifteen bits are the exponent bits, 'E', and thefinal 128 bits are the fraction 'F':

    S EEEEEEEEEEEEEEE FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0 1 15 16

    Single Double QuadrupleNo. of sign bit 1 1 1

    No. of exponent bit 8 11 15No. of fraction 23 52 111

    Total bits used 32 64 128

    Bias 127 1023 16383

    Table2 Basic IEEE floating point format

    Binary codeInternally, digital computers operate on binary numbers. When interfacing to humans, digital processors, e.g. pocketcalculators, communication is decimal-based. Input is done in decimal then converted to binary for internal processing.For output, the result has to be converted from its internal binary representation to a decimal form. Digital systemrepresents and manipulates not only binary number but also many other discrete elements of information.

    -Binary coded Decimal

    In computing and electronic systems, binary-coded decimal (BCD) is an encoding for decimal numbers in which eachdigit is represented by its own binary sequence. Its main virtue is that it allows easy conversion to decimal digits forprinting or display and faster decimal calculations. Its drawbacks are the increased complexity of circuits needed toimplement mathematical operations and a relatively inefficient encoding. It occupies more space than a pure binaryrepresentation.In BCD, a digit is usually represented by four bits which, in general, represent the values/digits/characters0-9

    To BCD-encode a decimal number using the common encoding, each decimal digit is stored in a four-bit nibble.

    Decimal: 0 1 2 3 4 5 6 7 8 9

    BCD: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001

    Thus, the BCD encoding for the number 127 would be:

    0001 0010 0111

    The position weights of the BCD code are 8, 4, 2, 1. Other codes (shown in the table) use position weights of 8, 4, -2, -1and 2, 4, 2, 1.

    An example of a non-weighted code is the excess-3 code where digit codes is obtained from

    their binary equivalent after adding 3. Thus the code of a decimal 0 is 0011, that of 6 is 1001, etc

  • DecimalDigit

    8 4 2 1 8 4 -2 -1 2 4 2 1 Excess-3Code code code code

    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 11 0 0 0 1 0 1 1 1 0 0 0 1 0 1 0 02 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 13 0 0 1 1 0 1 0 1 0 0 1 1 0 1 1 04 0 1 0 0 0 1 0 0 0 1 0 0 0 1 1 15 0 1 0 1 1 0 1 1 1 0 1 1 1 0 0 06 0 1 1 0 1 0 1 0 1 1 0 0 1 0 0 17 0 1 1 1 1 0 0 1 1 1 0 1 1 0 1 08 1 0 0 0 1 0 0 0 1 1 1 0 1 0 1 19 1 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0

    it is very important to understand the difference between the conversion of a decimal number to binary and the binarycoding of a decimal number. In each case, the final result is a series of bits. The bits obtained from conversion arebinary digit. Bits obtained from coding are combinations of 1s and 0s arranged according to the rule of the code used.e.g. the binary conversion of 13 is 1101; the BCD coding of 13 is 00010011

    - Error-Detection Codes

    Binary information may be transmitted through some communication medium, e.g. using wires or wireless media. Acorrupted bit will have its value changed from 0 to 1 or vice versa. To be able to detect errors at the receiver end, thesender sends an extra bit (parity bit) with the original binary message.

    A parity bit is an extra bit included with the n-bit binary message to make the total number of 1s in this message(including the parity bit) either odd or even. If the parity bit makes the total number of 1s an odd (even) number, it iscalled odd (even) parity. The table shows the required odd (even) parity for a 3-bit message

    Three-Bit Message Odd Parity Bit Even Parity BitX Y Z P P0 0 0 1 00 0 1 0 10 1 0 0 10 1 1 1 01 0 0 0 11 0 1 1 01 1 0 1 01 1 1 0 1

    No error is detectable if the transmitted message has 2 bits in error since the total number of 1s will remain even (orodd) as in the original message.

    In general, a transmitted message with even number of errors cannot be detected by the parity bit.

    - Gray code

    The Gray code consist of 16 4-bit code words to represent the decimal Numbers 0 to 15. For Gray code, successivecode words differ by only one bit from one to the next

  • Gray Code Decimal Equivalent0 0 0 0 00 0 0 1 10 0 1 1 20 0 1 0 30 1 1 0 40 1 1 1 50 1 0 1 60 1 0 0 71 1 0 0 81 1 0 1 91 1 1 1 101 1 1 0 111 0 1 0 121 0 1 1 131 0 0 1 141 0 0 0 15

    Character RepresentationEven though many people used to think of computers as "number crunchers", people figured out long ago that it's just asimportant to handle character data.

    Character data isn't just alphabetic characters, but also numeric characters, punctuation, spaces, etc. Most keys on thecentral part of the keyboard (except shift, caps lock) are characters. Characters need to represented. In particular, theyneed to be represented in binary. After all, computers store and manipulate 0's and 1's (and even those 0's and 1's are justabstractions. The implementation is typically voltages).

    Unsigned binary and two's complement are used to represent unsigned and signed integer respectively, because theyhave nice mathematical properties, in particular, you can add and subtract as you'd expect.

    However, there aren't such properties for character data, so assigning binary codes for characters is somewhat arbitrary.The most common character representation is ASCII, which stands for American Standard Code for InformationInterchange.

    There are two reasons to use ASCII. First, we need some way to represent characters as binary numbers (or,equivalently, as bitstring patterns). There's not much choice about this since computers represent everything in binary.

    If you've noticed a common theme, it's that we need representation schemes for everything. However, most importantly,we need representations for numbers and characters. Once you have that (and perhaps pointers), you can build upeverything you need.

    The other reason we use ASCII is because of the letter "S" in ASCII, which stands for "standard". Standards are goodbecause they allow for common formats that everyone can agree on.

    Unfortunately, there's also the letter "A", which stands for American. ASCII is clearly biased for the English languagecharacter set. Other languages may have their own character set, even though English dominates most of the computingworld (at least, programming and software).

    Even though character sets don't have mathematical properties, there are some nice aspects about ASCII. In particular,the lowercase letters are contiguous ('a' through 'z' maps to 9710 through 12210). The upper case letters are alsocontiguous ('A' through 'Z' maps to 6510 through 9010). Finally, the digits are contiguous ('0' through '9' maps to 4810through 5710).

  • Since they are contiguous, it's usually easy to determine whether a character is lowercase or uppercase (by checking ifthe ASCII code lies in the range of lower or uppercase ASCII codes), or to determine if it's a digit, or to convert a digitin ASCII to an integer value.

    ASCII Code (Decimal)0 nul 16 dle 32 sp 48 0 64 @ 80 P 96 ` 112 p1 soh 17 dc1 33 ! 49 1 65 A 81 Q 97 a 113 q2 stx 18 dc2 34 " 50 2 66 B 82 R 98 b 114 r3 etx 19 dc3 35 # 51 3 67 C 83 S 99 c 115 s4 eot 20 dc4 36 $ 52 4 68 D 84 T 100 d 116 t5 enq 21 nak 37 % 53 5 69 E 85 U 101 e 117 u6 ack 22 syn 38 & 54 6 70 F 86 V 102 f 118 v7 bel 23 etb 39 ' 55 7 71 G 87 W 103 g 119 w8 bs 24 can 40 ( 56 8 72 H 88 X 104 h 120 x9 ht 25 em 41 ) 57 9 73 I 89 Y 105 i 121 y10 nl 26 sub 42 * 58 : 74 J 90 Z 106 j 122 z11 vt 27 esc 43 + 59 ; 75 K 91 [ 107 k 123 {12 np 28 fs 44 , 60 < 76 L 92 108 l 124 |13 cr 29 gs 45 - 61 = 77 M 93 ] 109 m 125 }14 so 30 rs 46 . 62 > 78 N 94 ^ 110 n 126 ~15 si 31 us 47 / 63 ? 79 O 95 _ 111 o 127 del

    The characters between 0 and 31 are generally not printable (control characters, etc). 32 is the space character. Alsonote that there are only 128 ASCII characters. This means only 7 bits are required to represent an ASCII character.However, since the smallest size representation on most computers is a byte, a byte is used to store an ASCII character.The Most Significant bit(MSB) of an ASCII character is 0.

    ASCII Code (Hex)

    00 nul 10 dle 20 sp 30 0 40 @ 50 P 60 ` 70 p01 soh 11 dc1 21 ! 31 1 41 A 51 Q 61 a 71 q02 stx 12 dc2 22 " 32 2 42 B 52 R 62 b 72 r03 etx 13 dc3 23 # 33 3 43 C 53 S 63 c 73 s04 eot 14 dc4 24 $ 34 4 44 D 54 T 64 d 74 t05 enq 15 nak 25 % 35 5 45 E 55 U 65 e 75 u06 ack 16 syn 26 & 36 6 46 F 56 V 66 f 76 v07 bel 17 etb 27 ' 37 7 47 G 57 W 67 g 77 w08 bs 18 can 28 ( 38 8 48 H 58 X 68 h 78 x09 ht 19 em 29 ) 39 9 49 I 59 Y 69 i 79 y0a nl 1a sub 2a * 3a : 4a J 5a Z 6a j 7a z0b vt 1b esc 2b + 3b ; 4b K 5b [ 6b k 7b {0c np 1c fs 2c , 3c < 4c L 5c 6c l 7c |0d cr 1d gs 2d - 3d = 4d M 5d ] 6d m 7d }0e so 1e rs 2e . 3e > 4e N 5e ^ 6e n 7e ~0f si 1f us 2f / 3f ? 4f O 5f _ 6f o 7f del

    The difference in the ASCII code between an uppercase letter and its corresponding lowercase letter is 2016. This makesit easy to convert lower to uppercase (and back) in hex (or binary).

    Other Character Codes

    While ASCII is still popularly used, another character representation that was used (especially at IBM) was EBCDIC,which stands for Extended Binary Coded Decimal Interchange Code (yes, the word "code" appears twice). Thischaracter set has mostly disappeared. EBCDIC does not store characters contiguously, so this can create problemsalphabetizing "words".

  • One problem with ASCII is that it's biased to the English language. This generally creates some problems. One commonsolution is for people in other countries to write programs in ASCII.

    Other countries have used different solutions, in particular, using 8 bits to represent their alphabets, giving up to 256letters, which is plenty for most alphabet based languages (recall you also need to represent digits, punctuation, etc).

    However, Asian languages, which are word-based, rather than character-based, often have more words than 8 bits canrepresent. In particular, 8 bits can only represent 256 words, which is far smaller than the number of words in naturallanguages.

    Thus, a new character set called Unicode is now becoming more prevalent. This is a 16 bit code, which allows for about65,000 different representations. This is enough to encode the popular Asian languages (Chinese, Korean, Japanese,etc.). It also turns out that ASCII codes are preserved. What does this mean? To convert ASCII to Unicode, take all onebyte ASCII codes, and zero-extend them to 16 bits. That should be the Unicode version of the ASCII characters.

    The biggest consequence of using Unicode from ASCII is that text files double in size. The second consequence is thatendianness begins to matter again. Endianness is the ordering of individually addressable sub-units (words, bytes, oreven bits) within a longer data word stored in external memory. The most typical cases are the ordering of bytes within a16-, 32-, or 64-bit word, where endianness is often simply referred to as byte order. The usual contrast is between mostversus least significant byte first, called big-endian and little-endian respectively.

    Big-endian places the most significant bit, digit, or byte in the first, or leftmost, position. Little-endian places the mostsignificant bit, digit, or byte in the last, or rightmost, position. Motorola processors employ the big-endian approach,whereas Intel processors take the little-endian approach. Table bellow illustrates how the decimal value 47,572 would beexpressed in hexadecimal and binary notation (two octets) and how it would be stored using these two methods.Table : Endianess

    Number Big-Endian Little-EndianHexadecimal

    B9D4 B9D4 4D9BBinary

    10111001 10111001 1101010011010100 11010100 10111001

    With single bytes, there's no need to worry about endianness. However, you have to consider that with two bytequantities.

    While C and C++ still primarily use ASCII, Java has already used Unicode. This means that Java must create a bytetype, because char in Java is no longer a single byte. Instead, it's a 2 byte Unicode representation.

    Exercise1. The state of a 12-bit register is 010110010111. what is its content if it represents :

    i. Decimal digits in BCD code ii. Decimal digits in excess-3 code

    iii. Decimal digits in 8 4-2-1 code iv. Natural binary number

    2. The result of an experiment fall in the range -4 to +6. A scientist wishes to read the result into a computer and thenprocess them. He decides to use a 4-bit binary code to represents each of the possible inputs. Devise a 4-bit binary codeof representing numbers in the range of -4 to 6

    3. The (r-1)s complement of a base-6 numbers is called the 5s complement. Explain the procedure for obtaining the 5scomplement of base 6 numbers. Obtain the 5s complement of (3210)64. Design a three bit code to represent each of the six digits of the base 6 number system.

    5. Represent the decimal number 234.125 using the IEEE 32- bit (single) format

  • Binary Logic

    IntroductionBinary logic deals with variables that assume discrete values and with operators that assume logical meaning.

    While each logical element or condition must always have a logic value of either "0" or "1", we also need to haveways to combine different logical signals or conditions to provide a logical result.

    For example, consider the logical statement: "If I move the switch on the wall up, the light will turn on." At firstglance, this seems to be a correct statement. However, if we look at a few other factors, we realize that there's moreto it than this. In this example, a more complete statement would be: "If I move the switch on the wall up and thelight bulb is good and the power is on, the light will turn on."

    If we look at these two statements as logical expressions and use logical terminology, we can reduce the firststatement to:

    Light = Switch

    This means nothing more than that the light will follow the action of the switch, so that when the switch isup/on/true/1 the light will also be on/true/1. Conversely, if the switch is down/off/false/0 the light will also beoff/false/0.

    Looking at the second version of the statement, we have a slightly more complex expression:

    Light = Switch and Bulb and Power

    When we deal with logical circuits (as in computers), we not only need to deal with logical functions; we also needsome special symbols to denote these functions in a logical diagram. There are three fundamental logicaloperations, from which all other functions, no matter how complex, can be derived. These functions are namedand, or, and not. Each of these has a specific symbol and a clearly-defined behaviour.

    AND. The AND operation is represented by a dot(.) or by the absence of an operator. E.g. x.y=z xy=z are all read as xAND y=z. the logical operation AND is interpreted to mean that z=1 if and only if x=1 and y=1 otherwise z=0

    OR. The operation is represented by a + sign for example, x+y=z is interpreted as x OR y=z meaning that z=1 if x=1 ory=1 or if both x=1 and y=1. If both x and y are 0, then z=0

    NOT. This operation is represented by a bar or a prime. For example x= x =z is interpreted as NOT x =z meaning that zis what x is not

    It should be noted that although the AND and the OR operation have some similarity with the multiplication andaddition respectively in binary arithmetic , however one should note that an arithmetic variable may consist of manydigits. A binary logic variable is always 0 or 1.

    e.g. in binary arithmetic, 1+1=10 while in binary logic 1+1=1

    Basic GateThe basic building blocks of a computer are called logical gates or just gates. Gates are basic circuits that have at leastone (and usually more) input and exactly one output. Input and output values are the logical values true and false. Incomputer architecture it is common to use 0 for false and 1 for true. Gates have no memory. The value of the outputdepends only on the current value of the inputs. A useful way of describing the relationship between the inputs of gates

  • and their output is the truth table. In a truth table, the value of each output is tabulated for every possible combination ofthe input values.

    We usually consider three basic kinds of gates, and-gates, or-gates, and not-gates (or inverters).

    - The AND Gate

    The AND gate implements the AND function. With the gate shown to the left, both inputs must have logic 1 signalsapplied to them in order for the output to be a logic 1. With either input at logic 0, the output will be held to logic 0.

    The truth table for an and-gate with two inputs looks like this:

    x y | z-------

    0 0 | 00 1 | 01 0 | 01 1 | 1

    There is no limit to the number of inputs that may be applied to an AND function, so there is no functional limit tothe number of inputs an AND gate may have. However, for practical reasons, commercial AND gates are mostcommonly manufactured with 2, 3, or 4 inputs. A standard Integrated Circuit (IC) package contains 14 or 16 pins, forpractical size and handling. A standard 14-pin package can contain four 2-input gates, three 3-input gates, or two 4-input gates, and still have room for two pins for power supply connections.

    - The OR Gate

    The OR gate is sort of the reverse of the AND gate. The OR function, like its verbal counterpart, allows the output tobe true (logic 1) if any one or more of its inputs are true. Verbally, we might say, "If it is raining OR if I turn on thesprinkler, the lawn will be wet." Note that the lawn will still be wet if the sprinkler is on and it is also raining. This iscorrectly reflected by the basic OR function.

    In symbols, the OR function is designated with a plus sign (+). In logical diagrams, the symbol below designates theOR gate.

    The truth table for an or-gate with two inputs looks like this:

    x y | z-------

    0 0 | 00 1 | 11 0 | 11 1 | 1

    As with the AND function, the OR function can have any number of inputs. However, practical commercial OR gatesare mostly limited to 2, 3, and 4 inputs, as with AND gates.

  • - The NOT Gate, or Inverter

    The inverter is a little different from AND and OR gates in that it always has exactly one input as well as one output.Whatever logical state is applied to the input, the opposite state will appear at the output.

    The truth table for an inverter looks like this:

    x | y-----

    0 | 11 | 0

    The NOT function, as it is called, is necesasary in many applications and highly useful in others. A practical verbalapplication might be:

    The door is NOT locked = You may enter

    In the inverter symbol, the triangle actually denotes only an amplifier, which in digital terms means that it "cleans up"the signal but does not change its logical sense. It is the circle at the output which denotes the logical inversion. Thecircle could have been placed at the input instead, and the logical meaning would still be the same

    Combined gatesSometimes, it is practical to combine functions of the basic gates into more complex gates, for instance in order to savespace in circuit diagrams. In this section, we show some such combined gates together with their truth tables.

    - The nand-gate

    The nand-gate is an and-gate with an inverter on the output. So instead of drawing several gates like this:

    We draw a single and-gate with a little ring on the output like this:

    The nand-gate, like the and-gate can take an arbitrary number of inputs.

    The truth table for the nand-gate is like the one for the and-gate, except that all output values have been inverted:

  • x y | z-------

    0 0 | 10 1 | 11 0 | 11 1 | 0

    The truth table clearly shows that the NAND operation is the complement of the AND

    - The nor-gate

    The nor-gate is an or-gate with an inverter on the output. So instead of drawing several gates like this:

    We draw a single or-gate with a little ring on the output like this:

    The nor-gate, like the or-gate can take an arbitrary number of inputs.

    The truth table for the nor-gate is like the one for the or-gate, except that all output values have been inverted:

    x y | z-------

    0 0 | 10 1 | 01 0 | 01 1 | 0

    - The exclusive-or-gate

    The exclusive-or-gate is similar to an or-gate. It can have an arbitrary number of inputs, and its output value is 1 if andonly if exactly one input is 1 (and thus the others 0). Otherwise, the output is 0.

    We draw an exclusive-or-gate like this:

    The truth table for an exclusive-or-gate with two inputs looks like this:

  • x y | z-------

    0 0 | 00 1 | 11 0 | 11 1 | 0

    - The exclusive-Nor-gate

    The exclusive-Nor-gate is similar to an N or-gate. It can have an arbitrary number of inputs, and its output value is 1 ifand only if the two input are of the same values (1 and 1 or 0 and 0). Otherwise, the output is 0.

    We draw an exclusive-Nor-gate like this:

    The truth table for an exclusive-nor-gate with two inputs looks like this:

    x y | z-------

    0 0 | 10 1 | 01 0 | 01 1 | 1

    Let us limit ourselves to gates with n inputs. The truth tables for such gates have 2n lines. Such a gate is completelydefined by the output column in the truth table. The output column can be viewed as a string of 2n binary digits. Howmany different strings of binary digits of length 2n are there? The answer is 22n, since there are 2k different strings of kbinary digits, and if k=2n, then there are 22n such strings. In particular, if n=2, we can see that there are 16 differenttypes of gates with 2 inputs.

    Families of logic gatesThere are several different families of logic gates. Each family has its capabilities and limitations, its advantages anddisadvantages. The following list describes the main logic families and their characteristics. You can follow the links tosee the circuit construction of gates of each family.

    - Diode Logic (DL)

    Diode logic gates use diodes to perform AND and OR logic functions. Diodes have the property of easily passing anelectrical current in one direction, but not the other. Thus, diodes can act as a logical switch.

    Diode logic gates are very simple and inexpensive, and can be used effectively in specific situations. However, theycannot be used extensively, as they tend to degrade digital signals rapidly. In addition, they cannot perform a NOTfunction, so their usefulness is quite limited.

    - Resistor-Transistor Logic (RTL)

    Resistor-transistor logic gates use Transistors to combine multiple input signals, which also amplify and invert theresulting combined signal. Often an additional transistor is included to re-invert the output signal. This combinationprovides clean output signals and either inversion or non-inversion as needed.

  • RTL gates are almost as simple as DL gates, and remain inexpensive. They also are handy because both normal andinverted signals are often available. However, they do draw a significant amount of current from the power supply foreach gate. Another limitation is that RTL gates cannot switch at the high speeds used by today's computers, althoughthey are still useful in slower applications.

    Although they are not designed for linear operation, RTL integrated circuits are sometimes used as inexpensive small-signal amplifiers, or as interface devices between linear and digital circuits.

    - Diode-Transistor Logic (DTL)

    By letting diodes perform the logical AND or OR function and then amplifying the result with a transistor, we can avoidsome of the limitations of RTL. DTL takes diode logic gates and adds a transistor to the output, in order to provide logicinversion and to restore the signal to full logic levels.

    - Transistor-Transistor Logic (TTL)

    The physical construction of integrated circuits made it more effective to replace all the input diodes in a DTL gate witha transistor, built with multiple emitters. The result is transistor-transistor logic, which became the standard logic circuitin most applications for a number of years.

    As the state of the art improved, TTL integrated circuits were adapted slightly to handle a wider range of requirements,but their basic functions remained the same. These devices comprise the 7400 family of digital ICs.

    - Emitter-Coupled Logic (ECL)

    Also known as Current Mode Logic (CML), ECL gates are specifically designed to operate at extremely high speeds, byavoiding the "lag" inherent when transistors are allowed to become saturated. Because of this, however, these gatesdemand substantial amounts of electrical current to operate correctly.

    - CMOS Logic

    One factor is common to all of the logic families we have listed above: they use significant amounts of electrical power.Many applications, especially portable, battery-powered ones, require that the use of power be absolutely minimized. Toaccomplish this, the CMOS (Complementary Metal-Oxide-Semiconductor) logic family was developed. This familyuses enhancement-mode MOSFETs as its transistors, and is so designed that it requires almost no current to operate.

    CMOS gates are, however, severely limited in their speed of operation. Nevertheless, they are highly useful andeffective in a wide range of battery-powered applications.

    Most logic families share a common characteristic: their inputs require a certain amount of current in order to operatecorrectly. CMOS gates work a bit differently, but still represent a capacitance that must be charged or discharged whenthe input changes state. The current required to drive any input must come from the output supplying the logic signal.Therefore, we need to know how much current an input requires, and how much current an output can reliably supply,in order to determine how many inputs may be connected to a single output.

    However, making such calculations can be tedious, and can bog down logic circuit design. Therefore, we use a differenttechnique. Rather than working constantly with actual currents, we determine the amount of current required to driveone standard input, and designate that as a standard load on any output. Now we can define the number of standardloads a given output can drive, and identify it that way. Unfortunately, some inputs for specialized circuits require morethan the usual input current, and some gates, known as buffers, are deliberately designed to be able to drive more inputsthan usual. For an easy way to define input current requirements and output drive capabilities, we define two new terms:fan-in and fan-out

    Fan-in

    Fan-in is a term that defines the maximum number of digital inputs that a single logic gate can accept. Most transistor-transistor logic ( TTL ) gates have one or two inputs, although some have more than two. A typical logic gate has a fan-in of 1 or 2.

  • In some digital systems, it is necessary for a single TTL logic gate to drive several devices with fan-in numbers greaterthan 1. If the total number of inputs a transistor-transistor logic (TTL) device must drive is greater than 10, a devicecalled a buffer can be used between the TTL gate output and the inputs of the devices it must drive. A logical inverter(also called a NOT gate) can serve this function in most digital circuits.

    Fan-out

    Fan-out is a term that defines the maximum number of digital inputs that the output of a single logic gate can feed. Mosttransistor-transistor logic ( TTL ) gates can feed up to 10 other digital gates or devices. Thus, a typical TTL gate has afan-out of 10.

    In some digital systems, it is necessary for a single TTL logic gate to drive more than 10 other gates or devices. Whenthis is the case, a device called a buffer can be used between the TTL gate and the multiple devices it must drive. Abuffer of this type has a fan-out of 25 to 30. A logical inverter (also called a NOT gate) can serve this function in mostdigital circuits.

    Remember, fan-in and fan-out apply directly only within a given logic family. If for any reason you need to interfacebetween two different logic families, be careful to note and meet the drive requirements and limitations of both families,within the interface circuitry

    Boolean AlgebraOne of the primary requirements when dealing with digital circuits is to find ways to make them as simple as possible.This constantly requires that complex logical expressions be reduced to simpler expressions that nevertheless producethe same results under all possible conditions. The simpler expression can then be implemented with a smaller, simplercircuit, which in turn saves the price of the unnecessary gates, reduces the number of gates needed, and reduces thepower and the amount of space required by those gates.

    One tool to reduce logical expressions is the mathematics of logical expressions, introduced by George Boole in 1854and known today as Boolean Algebra. The rules of Boolean Algebra are simple and straight-forward, and can be appliedto any logical expression. The resulting reduced expression can then be readily tested with a Truth Table, to verify thatthe reduction was valid.

    Boolean algebra is an algebraic structure defined on a set of elements B, together with two binary operators(+, .)provided the following postulates are satisfied.

    1. Closure with respect to operator + and Closure with respect to operator .2. An identity element with respect to + designated by 0: X+0= 0+X=X

    An identity element with respect to . designated by 1: X.1= 1.X=X

    3. Commutative with respect to +: X=Y=Y+X

    Commutative with respect to .: X.Y=Y.X

    4. . distributive over +: X.(Y+Z)=X.Y+X.Z

    + distributive over .: X+(Y.Z)=(X+Y).(X+Z)

    5. For every element x belonging to B, there exist an element x or x called the complement of x such that x.x=0 and x+ x=1

    6. There exists at least two elements x,y belonging to B such that xy

    The two valued Boolean algebra is defined on a set B={0,1} with two binary operators + and.

  • X Y x+y0 0 00 1 11 0 11 1 0

    x x0 11 0

    X y x.y0 0 00 1 01 0 01 1 1

    Closure. from the tables, the result of each operation is either 0 or 1 and 1 ,0 belongs to B

    Identity. From the truth table we see that 0 is the identity element for + and 1 is the identity element for . .

    Commutative law is obvious from the symmetry of binary operators table.

    Distributive Law. x.(y+z)=x.y+x.z

    x y z y+z x.(y+z) x.y x.z x.y+x.z0 0 0 0 0 0 0 00 0 1 1 0 0 0 00 1 0 1 0 0 0 00 1 1 1 0 0 0 01 0 0 0 0 0 0 01 0 1 1 1 0 1 11 1 0 1 1 1 0 11 1 1 1 1 1 1 1

    Distributive of + over . can be shown as in the truth table above

    From the complement table we can see that x+ x=1 i.e 1+0=1 and x. x=0 i.e 1.0=0

    Principle of duality of Boolean algebra

    The principle of duality state that every algebraic expression which can be deduced from the postulates of Booleanalgebra remains valid if the operators and the identity elements are interchanged. This mean that the dual of anexpression is obtained changing every AND(.) to OR(+), every OR(+) to AND(.) and all 1's to 0's and vice-versa

    Laws of Boolean Algebra

    Postulate 2 :

    (a) 0 + A = A (b) 1.A = A

    Postulate 5 :

    (a) A + A =1 (b) A. A=0

    Theorem1 : Identity Law

    (a) A + A = A (b) A A = A

    Theorem2

    (a) 1 + A = 1 (b) 0. A = 0

    Theorem3: involution

    A=A

  • Postulate 3 : Commutative Law

    (a) A + B = B + A (b) A B = B A

    Theorem4: Associate Law

    (a) (A + B) + C = A + (B + C) (b) (A B) C = A (B C)

    Postulate4: Distributive Law

    (a) A (B + C) = A B + A C (b) A + (B C) = (A + B) (A + C)

    Theorem5 : De Morgan's Theorem

    (a) (A+B)= AB (b) (AB)= A+ B

    Theorem6 : Absorption

    (a) A + A B = A (b) A (A + B) = A

    Prove Theorem 1 : (a)X+X=Xx+x=(X+X).1 by postulate 2b

    =(x+x)(x+x) 5a=x+xx 4b=x+0 5b=x 2a

    Prove Theorem 1 : (b)X.X=Xxx=(X.X)+0 by postulate 2a

    =x.x+x.x 5b=x(x+x) 4a=x.1 5a=x 2b

    Prove Theorem 2 : (a)X+1=Xx+1=1.(X+1) by postulate 2b

    (x+x)=(x+1) 5a=x+x.1 4b=x+ x 2b=1 5a

    Prove Theorem 2 : (b)X.0=0x.0=0+(X.0) by postulate 2a

    (x.x)=(x.0) 5b=x.x+0 4a=x.x 2a=0 5b

    Prove Theorem 6 : (a)X+xy=Xx+xy=x.1+xy by postulate 2b

    =x(1+y) 4b=x(y+1) 3a=x.1 2b=x 2b

  • Prove Theorem 6 : (b)X(x+y)=XX(x+y)=(x+0).(x+y) by postulate 2a

    =x+0.y 4a=x +0 2a=x 2a

    Using the laws given above, complicated expressions can be simplified.

    Combinational circuitIntroductionThe combinational circuit consist of logic gates whose outputs at any time is determined directly from the presentcombination of input without any regard to the previous input. A combinational circuit performs a specific informationprocessing operation fully specified logically by a set of Boolean functions.

    A combinatorial circuit is a generalized gate. In general such a circuit has m inputs and n outputs. Such a circuit canalways be constructed as n separate combinatorial circuits, each with exactly one output. For that reason, some textsonly discuss combinatorial circuits with exactly one output. In reality, however, some important sharing of intermediatesignals may take place if the entire n-output circuit is constructed at once. Such sharing can significantly reduce thenumber of gates required to build the circuit.

    When we build a combinatorial circuit from some kind of specification, we always try to make it as good as possible.The only problem is that the definition of "as good as possible" may vary greatly. In some applications, we simply wantto minimize the number of gates (or the number of transistors, really). In other, we might be interested in as short adelay (the time it takes a signal to traverse the circuit) as possible, or in as low power consumption as possible. Ingeneral, a mixture of such criteria must be applied.

    Describing existing circuits using Truth tablesTo specify the exact way in which a combinatorial circuit works, we might use different methods, such as logicalexpressions or truth tables.

    A truth table is a complete enumeration of all possible combinations of input values, each one with its associated outputvalue.

    When used to describe an existing circuit, output values are (of course) either 0 or 1. Suppose for instance that we wishto make a truth table for the following circuit:

    All we need to do to establish a truth table for this circuit is to compute the output value for the circuit for each possiblecombination of input values. We obtain the following truth table:

    w x y | a b-----------

    0 0 0 | 0 1

  • 0 0 1 | 0 10 1 0 | 1 10 1 1 | 1 01 0 0 | 1 11 0 1 | 1 11 1 0 | 1 11 1 1 | 1 0

  • Specifying circuits to buildWhen used as a specification for a circuit, a table may have some output values that are not specified, perhaps becausethe corresponding combination of input values can never occur in the particular application. We can indicate suchunspecified output values with a dash -.

    For instance, let us suppose we want a circuit of four inputs, interpreted as two nonnegative binary integers of twobinary digits each, and two outputs, interpreted as the nonnegative binary integer giving the quotient between the twoinput numbers. Since division is not defined when the denominator is zero, we do not care what the output value is inthis case. Of the sixteen entries in the truth table, four have a zero denominator. Here is the truth table:

    x1 x0 y1 y0 | z1 z0-------------------

    0 0 0 0 | - -0 0 0 1 | 0 00 0 1 0 | 0 00 0 1 1 | 0 00 1 0 0 | - -0 1 0 1 | 0 10 1 1 0 | 0 00 1 1 1 | 0 01 0 0 0 | - -1 0 0 1 | 1 01 0 1 0 | 0 11 0 1 1 | 0 01 1 0 0 | - -1 1 0 1 | 1 11 1 1 0 | 0 11 1 1 1 | 0 1

    Unspecified output values like this can greatly decrease the number of circuits necessary to build the circuit. The reasonis simple: when we are free to choose the output value in a particular situation, we choose the one that gives the fewesttotal number of gates.

    Circuit minimization is a difficult problem from complexity point of view. Computer programs that try to optimizecircuit design apply a number of heuristics to improve speed. In this course, we are not concerned with optimality. Weare therefore only going to discuss a simple method that works for all possible combinatorial circuits (but that can wastelarge numbers of gates).

    A separate single-output circuit is built for each output of the combinatorial circuit.

    Our simple method starts with the truth table (or rather one of the acceptable truth tables, in case we have a choice). Ourcircuit is going to be a two-layer circuit. The first layer of the circuit will have at most 2n AND-gates, each with n inputs(where n is the number of inputs of the combinatorial circuit). The second layer will have a single OR-gate with as manyinputs as there are gates in the first layer. For each line of the truth table with an output value of 1, we put down a AND-gate with n inputs. For each input entry in the table with a 1 in it, we connect an input of the AND-gate to thecorresponding input. For each entry in the table with a 0 in it, we connect an input of the AND-gate to the correspondinginput inverted.

    The output of each AND-gate of the fist layer is then connected to an input of the OR-gate of the second layer.

    As an example of our general method, consider the following truth table (where a - indicates that we don't care whatvalue is chosen):

  • x y z | a b-----------

    0 0 0 | - 00 0 1 | 1 10 1 0 | 1 -0 1 1 | 0 01 0 0 | 0 11 0 1 | 0 -1 1 0 | - -1 1 1 | 1 0

    The first step is to arbitrarily choose values for the undefined outputs. With out simple method, the best solution is tochoose a 0 for each such undefined output. We get this table:x y z | a b-----------

    0 0 0 | 0 00 0 1 | 1 10 1 0 | 1 00 1 1 | 0 01 0 0 | 0 11 0 1 | 0 01 1 0 | 0 01 1 1 | 1 0

    Now, we have to build two separate single-output circuits, one for the a column and one for the b column.

    A=xyz+xyz+xyz

    B=xyz+xyz

    For the first column, we get three 3-input AND-gates in the first layer, and a 3-input OR-gate in the second layer. We getthree AND -gates since there are three rows in the a column with a value of 1. Each one has 3-inputs since there arethree inputs, x, y, and z of the circuit. We get a 3-input OR-gate in the second layer since there are three AND -gates inthe first layer.

    Here is the complete circuit for the first column:

    For the second column, we get two 3-input AND -gates in the first layer, and a 2-input OR-gate in the second layer. Weget two AND-gates since there are two rows in the b column with a value of 1. Each one has 3-inputs since again thereare three inputs, x, y, and z of the circuit. We get a 2-input AND-gate in the second layer since there are two AND-gatesin the first layer.

    Here is the complete circuit for the second column:

  • Now, all we have to do is to combine the two circuits into a single one:

    While this circuit works, it is not the one with the fewest number of gates. In fact, since both output columns have a 1 inthe row correspoding to the inputs 0 0 1, it is clear that the gate for that row can be shared between the two subcircuits:

    In some cases, even smaller circuits can be obtained, if one is willing to accept more layers (and thus a higher circuitdelay).

  • Boolean functionsOperations of binary variables can be described by mean of appropriate mathematical function called Boolean function.A Boolean function define a mapping from a set of binary input values into a set of output values. A Boolean function isformed with binary variables, the binary operators AND and OR and the unary operator NOT.

    For example , a Boolean function f(x1,x2,x3,,xn) =y defines a mapping from