Part 1

**Reference Books:**

**DATA STRUCTURES****Just as learning to design programs is important, therefore is theunderstanding of the exactly format and also usage that data. Allprograms usage some kind of data. To style programs i beg your pardon workcorrectly, a great understanding of how data is structured will berequired. **

**This module introduce you come the various forms of data usedby programs. We shall investigate just how the data is stored,accessed and its common usage in ~ programs. **

**A computer stores details in Binary format. Binary is anumber system which offers BITS to keep data. **

**BITS****A little bit is the smallest element of information used through a computer.A little holds among TWO feasible values, **

You are watching: How many bits is a character

You are watching: How many bits is a character

Value | Meaning |

0 | OFF |

1 | ON |

A little which is off is also considered to be FALSE or no SET;a bit which is on is also considered to be TRUE or SET.

Because a solitary bit deserve to only keep two values, bits arecombined with each other into big units in bespeak to hold a greaterrange the values.

**NIBBLE****A nibble is a team of 4 bits. This offers a maximum number of16 feasible different values. **

** 2 ** 4 = 16 (2 come the strength of the variety of bits)It is useful, when taking care of groups that bits, to determinewhich little of the group has the least value, and which bit has actually themost or biggest value. **

**The Least far-reaching Bit and The most Sigificant Bit****This is considered to be bit 0, and is constantly drawn at the extremeright. The Most far-ranging bit is constantly shown on the extremeleft, and is the little with the best value. **

**The diagram listed below shows a NIBBLE, and also each bits place anddecimal weight value (for much more information, above the module onNumber Systems). **

** 3 2 1 0 bit Number +---+---+---+---+ | | | | | +---+---+---+---+ 8 4 2 1 Decimal Weighting value MSB LSBLets consider an example of convert binary worths intodecimal. **

** bit 3 2 1 0 worth 1 0 1 1 bit 3 is set, therefore it has a decimal weight value of 8 bit 2 is no set, therefore it has actually a decimal weight worth of 0 bit 1 is set, so it has a decimal weight worth of 2 bit 0 is set, so it has actually a decimal weight value of 1 including up all the decimal weight worths for every bit= 11 so 1011 in binary is 11 in decimal!For an ext examples, consult the module top top Number Systems. **

**BYTES****Bytes space a group of 8 bits. This comprises 2 nibbles, asshown below. **

** 7 6 5 4 3 2 1 0 little bit Number +---+---+---+---+---+---+---+---+ | | | | | | | | | +---+---+---+---+---+---+---+---+ 128 64 32 16 8 4 2 1 Decimal Weighting worth MSB LSBBytes are regularly used to keep CHARACTERS.They can additionally be provided to save numeric values, **

** 0 come 255 -127 to +128**

**Binary Coded Decimal **

**Binary code decimal digits (0-9) are represented using 4 bits.The valid combinations that bits and their corresponding values space**

Binary worth | Digit |

0000 | 0 |

0001 | 1 |

0010 | 2 |

0011 | 3 |

0100 | 4 |

0101 | 5 |

0110 | 6 |

0111 | 7 |

1000 | 8 |

1001 | 9 |

The binary combine 1010 come 1111 are invalid and also are notused.

If the computer system stores one BCD digit per byte, that callednormal BCD. The unused nibble may be either all 0"s or all 1"s.

**If 2 BCD digits space stored per byte, its dubbed PackedBCD**. This wake up in data transmission wherein numbers room beingtransmitted end a communications link. Packed BCD reduce theamount of time invested transmitting the numbers, together each data bytetransmitted outcomes in the sending of 2 BCD digits.

Consider the storing of the number 56 in packed BCD format.

7 6 5 4 3 2 1 0 little Number +---+---+---+---+---+---+---+---+ | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | +---+---+---+---+---+---+---+---+ MSB LSBThe top nibble stop the worth 5, whilst the reduced nibbleholds the worth 6.

**Status and Boolean Variables****BOOLEAN variables usage a single bit to host their value, so canonly assume among two possible states. This is either 0(considered to it is in FALSE), or 1 (considered to it is in TRUE). **

**The computer system handles every boolean variable together a single bit. Ifthe little is TRUE, climate is has a value of 1. If the little bit is FALSE,then it has the worth 0. **

**When a group of bits room grouped with each other to form a limitedrange of values, this is recognized as a STATUS** variable.

Consider the case in a regime where we need to keep track ofthe variety of minutes a phone line is busy for (within thelimited variety of 0 come 60). This go not call for the use of afull integer, so part programming languages enable you come specifythe number of bits supplied to allocate to variables v limitedranges.

The advantage of this approach, is that the storage an are ofstatus variables deserve to be merged together into a solitary 16 or 32bits, leading to a saving of space.

Consider wherein a computer allocates 16 bits of warehouse perstatus variable. If we had actually three standing variables, the spaceconsumed would be 48 bits. BUT, if all the condition variables couldbe linked and fitted right into a single 16 bits that storage, we couldsave 32 bits that memory. This is very important in real-timesystems whereby memory an are is in ~ a premium.

Consider the adhering to diagram, which illustrates the packingof boolean and also status variables together into a solitary byte.

7 6 5 4 3 2 1 0 bit Number +---+---+---+---+---+---+---+---+ | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 0 | +---+---+---+---+---+---+---+---+ | | | | | | | +--- neighborhood call/TOLL contact (bit 0) | | +------- expansion busy/free (bit 1) | +------------------- minute (bits 2-4) +----------------------- extension diverted/TRUE/FALSE

**The American standard Code for info Interchange****ASCII is a computer system code which supplies 128 different encodingcombinations of a team of seven bits (27 = 128) come represent, **

**personalities A to Z, both upper and also lower case special characters, number 0 come 9 special regulate codes supplied for an equipment control**

Lets now look in ~ the encoding method. The table listed below showsthe little bit combinations compelled for every character.

00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 0A | 0B | 0C | 0D | 0E | 0F | |

00 | NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | TAB | LF | VT | FF | CR | SO | SI |

10 | DLE | DC1 | DC2 | DC3 | DC4 | NAK | SYN | ETB | CAN | EM | SUB | ESC | FS | GS | RS | US |

20 | ! | " | # | $ | % | & | " | ( | ) | * | + | , | - | . | / | |

30 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | : | ; | ? | |||

40 | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | |

50 | P | Q | R | S | T | U | V | W | X | Y | Z | < | > | ^ | _ | |

60 | ` | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o |

70 | p | q | r | s | t | u | v | w | x | y | z | ~ | DEL |

See more: Distance From Marco Island To Key West, Fl, Distance From Marco Island, Fl To Key West, Fl

A computer usually stores details in eight bits. Theeighth little bit is unused in ASCII, for this reason is normally collection to 0. Somesystems might use the eight little to implement graphic or differentlanguage symbols, ie, Greek characters.

**Control codes are offered in communications and printers. Theymay be created from an ASCII keyboard by holding under the CTRL**(control) vital and pressing another vital (A come Z, to add {, , >, ^,Example code the message string "Hello." in ASCII usinghexadecimal digits.

H = 48 e = 65 l = 6C together = 6C o = 6F . = 2Ethus the cable is stood for by the byte succession

48 65 6C 6C 6F 2E

**CHARACTERS****Characters room non-numeric symbols used to convey language andmeaning. In English, lock are merged with other personalities toform words. Examples of characters are; **

** a b c d e f g h ns j k l m n o ns q r s t u v w x y z A B C D E F G H ns J K l M N O p Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ^ & * ( ) _ - = + | ` , . / ; " < > : " ? A computer system system normally stores personalities using the ASCIIcode. Each character is stored using eight bits that information,giving a total variety of 256 different personalities (2**8 = 256). **

**In the high level language Pascal, characters are characterized andused as follows, **

** var plus_symbol : char; start plus_symbol := "+"; Variables used in a Pascal regime are declared after thekeyword var**. The over example declares the variable plus_symbolto it is in a character type, thus eight bits of memory storage areallocated to save its value (as however undetermined).

Inside the main body of the program, after the keyword **begin**,the statement shown assigns the symbol **+** come the charactervariable plus_symbol. This is equivalent to save theASCII worth 2B hexadecimal in the eight bits of memory allocatedto the variable plus_symbol.

**TEXT STRINGS****Text strings are a succession of characters (ie, words or multi-character symbols). Every character is stored one ~ the other,each occupying eight bits of memory storage. **

**The message string Hello would be save on computer as adheres to **

** +------+ | 48 | +------+ | 65 | +------+ | 6C | +------+ | 6C | +------+ | 6F | +------+ In Turbo Pascal, text strings room defined and also used together follows,**

** var text_message : string<22>; start text_message := "Welcome to text strings"; The above example declares the change text_message to be astring form of up to 22 characters long (but no more!). Eightbits of memory storage space allocated to keep each character inthe string (a total of 22 bytes), through the worth in every byte asyet undetermined. **

**Inside the key body of the program, after the keyword begin,the statement displayed assigns the article Welcome to textstrings to the string variable text_message. Thisstores the ASCII value of every character into each successivebyte of memory allocated come the variable text_message**.

**INTEGERS ****Numeric information cannot efficiently be stored utilizing the ASCII format. Imagine save on computer thenumber 123,769 making use of ASCII. This would consume 6 bytes, and also itwould be daunting to tell if the number was optimistic or negative(though we might precede it through the character + or -). **

**A much more efficient method of storing numeric info is come usea various encoding scheme. The encoding scheme in most use isshown below, **

** Bits** 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +---+--------------------------------------------+ | S | Numeric value in Binary |+---+--------------------------------------------+ S = Sign little Integers store entirety numbers only! They carry out not containfractional parts. Think about the instances below,

**ValidInvalid **123.987 00.0 278903123.09 The sign little bit (which is little bit 15) indicates whether the number ispositive or negative. A reasonable 1 indicates negative, a reasonable 0indicates positive.

The number is convert to binary and stored in bits 0 come 14of the two bytes.

**Example** save the worth +263 together an integer value. 1) The sign little is 0. 2) The decimal value +263 is 100000111 in binary. For this reason the warehouse in memory of the integer +263 look at like, Bits 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +---+---------------------------------------------+ | 0 | 0 0 0 0 0 0 1 0 0 0 0 0 1 1 1 | +---+---------------------------------------------+ as soon as storing an unfavorable numbers, the number is stored using thetwo"s enhance format.

In Pascal, integers space defined and also used together follows,

var whole_number : integer; start whole_number := 1267; The example declares the change whole_number to be aninteger type, therefore sixteen bits of memory storage are allocatedto keep its worth (as however undetermined).

Inside the key body the the program, after the keyword **begin**,the statement presented assigns the numeric worth 1267 come the integervariable whole_number. This is tantamount to storing thebit mix 0000010011110011 in the sixteen bits that memoryallocated to the variable whole_number.

Signed integers making use of 16 bits have actually a number selection of,

-32768 to +32767 (+-2^15) to store larger integer values would require more bits. Somesystems and languages additionally support the use of unsigned integers,which are reputed to be optimistic only.

**FLOATING allude NUMBERS****There space two troubles with integers; they can not expressfractions, and also the range of the number is limited to the numberof bits used. An efficient method of storing fractions is referred to as thefloating point method, which involves splitting the portion intotwo parts, an exponent and a mantissa. **

**The exponent represents a value increased to the strength of 2. **

**The mantissa to represent a spring value between 0 and 1. **

**Consider the number **

** 12.50 The number is an initial converted into the layout **

** 2n * 0.xxxxxx where n **represents the exponent and also 0.xxxxx is themantissa.

The computer system industry agreed top top a traditional for the storageof floating allude numbers. The is dubbed the IEEE 754 standard,and provides 32 bits of memory (for solitary precision), or 64 bits(for dual precision accuracy). The solitary precision formatlooks like,

Bits 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +---+-----------------------+---------------------------------------------------------------------+ | S | Exponent value | Mantissa value | +---+-----------------------+---------------------------------------------------------------------+ S = Sign bit The sign little bit is 1 because that a negative mantissa, and also 0 because that apositive mantissa.

The exponent uses a bias of 127.

The mantissa is stored together a binary value using an encodingtechnique.

**Working the end the FP bit patterns****The number we have is **

**12.5 i m sorry expressed as fraction to the strength of 2 is, **

** 12.5 / 2 = 6.25 6.25 / 2 = 3.125 3.125 / 2 = 1.5625 1.5625 / 2 = 0.78125 NOTE: Keep dividing by 2 it spins a portion between 0 and 1results. The fraction is the mantissa value, the number ofdivisions is the exponent value. **

**thus our values currently are, **

** 0.78125 * 24 The exponent little bit pattern is stored utilizing an overfill of 127.This way that this worth is added to the exponent as soon as storing(and subtracted when removing). **

**The exponent little pattern to save is, **

** 4 + 127 = 131 = "10000011" as the mantissa is a positive value, the sign little bit is 0. **

**The mantissa is a small more complex to job-related out. Eachbit represents 2 to the power of a an unfavorable number. It lookslike, **

** 1st bit that mantissa = 0.5 2nd = 0.25 third = 0.125 fourth = 0.0625 5th = 0.03125 etc The mantissa number value we have actually is 0.78125, i m sorry in binaryis **

**11001000000000000000000(0.5 + 0.25 + 0.03125) How-ever, to do matters even more complicated, the mantissais normalized, by moving the little patterns to the left (each shiftsubtracts one native the exponent value) it rotates the first 1 dropsoff. **

**The resulting sample is climate stored. **

**The mantissa currently becomes **

** 10010000000000000000000 and also the exponent is readjusted to end up being **

** 131 - 1 = 130 = "10000010" The final assembled style is, **

** Bits 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +--+-----------------------+---------------------------------------------------------------------+ | 0| 1 0 0 0 0 0 1 0| 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | +--+-----------------------+---------------------------------------------------------------------+ S Exponent Mantissa now lets transform the following storage format earlier into adecimal number. **

** Bits 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +--+-----------------------+---------------------------------------------------------------------+ | 1| 1 0 0 0 0 0 1 1| 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 | +--+-----------------------+---------------------------------------------------------------------+ S Exponent Mantissa This provides a an adverse number v an exponent value of, **

** 131 - 127 = 4 and also a mantissa worth of, **

** 1.0 + 0.5 + 0.0625 = 1.5625 (the 1.0 originates from the little which was shifted off once themantissa was normalized ), therefore the number is, **

** -1.5625 * 24 = -25.0 The numeric range for floating point numbers utilizing theIEEE-754 method, making use of 32 bits, is **

** +- 0.838860808 * 2-128 come +- 0.838860808 * 2127 or, in decimal, **

** 2.4652 * 10-39 come 1.4272 * 1038 In Pascal, floating suggest numbers are defined and used asfollows, **

**var fp_number : real; start fp_number := 12.50; The instance declares the variable fp_number to be afloating- suggest type, hence thirty-two bits of memory storage areallocated to keep its worth (as yet undetermined). **

**Inside the main body that the program, ~ the keyword begin**,the statement presented assigns the numeric worth 12.50 come the realvariable fp_number. This is indistinguishable to save the bitcombinations 01000001010010000000000000000000 in the thirty-twobits of memory allocated come the variable fp_number.

The advantages of save floating point numbers in this wayare,

multiplication is perform by including exponents and mantissa"s division is perform by subtracting exponents and mantissa"s the is simple to compare 2 numbers to see which is the greater or lesser huge number varieties are stored using relatively few bitsThe defect of the storage style are,

errors are developed by moving the mantissa bits switch backwards and forwards bring away time