Part 1

**Reference Books:**

**DATA STRUCTURES****Just as discovering to design programs is important, for this reason is theunderstanding of the exactly format and also usage the data. Allprograms use some form of data. To design programs which workcorrectly, a good understanding of exactly how data is structured will certainly berequired. **

**This module introduce you to the various creates of data usedby programs. Us shall investigate exactly how the data is stored,accessed and its usual usage in ~ programs. **

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

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

You are watching: How many bytes is a character

You are watching: How many bytes is a character

Value | Meaning |

0 | OFF |

1 | ON |

A little which is off is additionally considered to be FALSE or no SET;a little which is ~ above is additionally considered to be TRUE or SET.

Because a single bit have the right to only keep two values, bits arecombined together into big units in order to hold a greaterrange the values.

**NIBBLE****A nibble is a group of 4 bits. This provides a preferably number of16 possible different values. **

** 2 ** 4 = 16 (2 come the strength of the variety of bits)It is useful, when dealing with groups the bits, come determinewhich bit of the team has the the very least value, and which bit has themost or best value. **

**The Least far-reaching Bit and also The most Sigificant Bit****This is understood to be bit 0, and also is constantly drawn at the extremeright. The Most far-reaching bit is constantly shown ~ above the extremeleft, and also is the bit with the greatest value. **

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

** 3 2 1 0 little 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, so it has actually a decimal weight value of 8 little bit 2 is not set, so it has actually a decimal weight value of 0 little bit 1 is set, therefore it has a decimal weight worth of 2 little bit 0 is set, so it has actually a decimal weight worth of 1 adding up every the decimal weight worths for each bit= 11 so 1011 in binary is 11 in decimal!For much more examples, above the module ~ above Number Systems. **

**BYTES****Bytes are a grouping of 8 bits. This comprises two nibbles, asshown below. **

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

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

**Binary Coded Decimal **

**Binary password decimal digits (0-9) are stood for using 4 bits.The precious combinations of bits and their corresponding values are**

Binary value | Digit |

0000 | 0 |

0001 | 1 |

0010 | 2 |

0011 | 3 |

0100 | 4 |

0101 | 5 |

0110 | 6 |

0111 | 7 |

1000 | 8 |

1001 | 9 |

The binary combinations 1010 to 1111 are invalid and are notused.

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

**If 2 BCD digits room stored every byte, its referred to as PackedBCD**. This wake up in data transmission where numbers are beingtransmitted over a communications link. Packed BCD to reduce theamount the time spent transmitting the numbers, as each data bytetransmitted outcomes in the sending out of two BCD digits.

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

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

**Status and also Boolean Variables****BOOLEAN variables usage a single bit to organize their value, for this reason canonly assume one of two possible states. This is either 0(considered to be FALSE), or 1 (considered to it is in TRUE). **

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

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

Consider the case in a program where we have to keep track ofthe variety of minutes a phone heat is busy for (within thelimited selection of 0 come 60). This walk not need the usage of afull integer, so some programming languages allow you come specifythe number of bits offered to allocate to variables through limitedranges.

The benefit of this approach, is that the storage space ofstatus variables deserve to be combined together right into a single 16 or 32bits, leading to a conserving of space.

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

Consider the complying with diagram, which illustrates the packingof boolean and status variables together into a single byte.

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

**The American typical Code for info Interchange****ASCII is a computer system code which uses 128 different encodingcombinations the a team of seven bits (27 = 128) to represent, **

**personalities A come Z, both upper and lower situation special characters, number 0 come 9 special manage codes used for maker control**

Lets currently look in ~ the encoding method. The table listed below showsthe little combinations forced for each 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: A Song Form In Which The Same Melody Is Repeated For Every Stanza Of Text Is Called:

A computer usually stores info in eight bits. Theeighth bit is unused in ASCII, hence is normally set to 0. Somesystems might use the eight little bit to implement graphic or differentlanguage symbols, ie, Greek characters.

**Control password are supplied in communications and also printers. Theymay be produced from an ASCII keyboard by holding under the CTRL**(control) an essential and pressing another crucial (A come Z, plus {, , >, ^,Example password the text string "Hello." in ASCII usinghexadecimal digits.

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

48 65 6C 6C 6F 2E

**CHARACTERS****Characters space non-numeric symbols supplied to convey language andmeaning. In English, castle are linked with other characters toform words. Examples of characters are; **

** a b c d e f g h i 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 i J K together M N O ns Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! # $ % ^ & * ( ) _ - = + | ` , . / ; " < > : " ? A computer system generally stores characters using the ASCIIcode. Each character is stored using eight bits the information,giving a total variety of 256 different characters (2**8 = 256). **

**In the high level language Pascal, personalities are identified andused as follows, **

** var plus_symbol : char; start plus_symbol := "+"; Variables used in a Pascal routine are declared after thekeyword var**. The above example declares the variable plus_symbolto be a personality type, therefore eight bits of memory storage areallocated to save its value (as however undetermined).

Inside the main body that the program, after the keyword **begin**,the statement displayed assigns the prize **+** come the charactervariable plus_symbol. This is indistinguishable to save on computer theASCII value 2B hexadecimal in the eight bits of memory allocatedto the change plus_symbol.

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

**The text string Hello would be save on computer as complies with **

** +------+ | 48 | +------+ | 65 | +------+ | 6C | +------+ | 6C | +------+ | 6F | +------+ In Turbo Pascal, message strings space defined and used together follows,**

** var text_message : string<22>; begin text_message := "Welcome to text strings"; The above example declares the variable text_message to it is in astring kind of as much as 22 personalities long (but no more!). Eightbits of storage storage room allocated to save each personality inthe wire (a complete of 22 bytes), with the value in every byte asyet undetermined. **

**Inside the key body the the program, after ~ the keyword begin,the statement shown assigns the blog post Welcome to textstrings come the string change text_message. Thisstores the ASCII worth of each character right into each successivebyte of storage allocated come the change text_message**.

**INTEGERS ****Numeric details cannot successfully be stored making use of the ASCII format. Imagine save thenumber 123,769 using ASCII. This would consume 6 bytes, and itwould be challenging to tell if the number was hopeful or negative(though we could precede it with the character + or -). **

**A more efficient way of save numeric information is to usea various encoding scheme. The encoding plan in many use isshown below, **

** Bits** 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +---+--------------------------------------------+ | S | Numeric worth in Binary |+---+--------------------------------------------+ S = Sign little Integers store totality numbers only! They perform not containfractional parts. Take into consideration 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 shows negative, a reasonable 0indicates positive.

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

**Example** store the value +263 as an essence value. 1) The sign little bit is 0. 2) The decimal value +263 is 100000111 in binary. Hence the warehouse in memory of the essence +263 looks 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 | +---+---------------------------------------------+ when storing negative numbers, the number is stored making use of thetwo"s match format.

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

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

Inside the main body that the program, ~ the keyword **begin**,the statement shown assigns the numeric value 1267 to the integervariable whole_number. This is indistinguishable to save thebit mix 0000010011110011 in the 16 bits that memoryallocated to the change whole_number.

Signed integers making use of 16 bits have a number range of,

-32768 come +32767 (+-2^15) come store larger integer worths would require more bits. Somesystems and also languages also support the use of unsigned integers,which are deemed to be confident only.

**FLOATING point NUMBERS****There space two difficulties with integers; they cannot expressfractions, and the variety of the number is limited to the numberof bits used. An efficient method of storing fractions is called thefloating suggest method, i m sorry involves dividing the portion intotwo parts, one exponent and a mantissa. **

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

**The mantissa to represent a fractional value in between 0 and also 1. **

**Consider the number **

** 12.50 The number is first converted into the format **

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

The computer system industry agreed ~ above a standard for the storageof floating suggest numbers. That is referred to as the IEEE 754 standard,and uses 32 bits of storage (for single precision), or 64 bits(for double 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 worth | Mantissa value | +---+-----------------------+---------------------------------------------------------------------+ S = Sign little bit The sign little is 1 because that a an unfavorable mantissa, and 0 because that apositive mantissa.

The exponent uses a bias of 127.

The mantissa is stored as a binary value making use of an encodingtechnique.

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

**12.5 i m sorry expressed as portion 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 splitting by 2 it spins a fraction between 0 and also 1results. The portion is the mantissa value, the number ofdivisions is the exponent value. **

**thus ours values currently are, **

** 0.78125 * 24 The exponent little bit pattern is stored using an excess of 127.This method that this worth is included to the exponent once storing(and subtracted once removing). **

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

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

**The mantissa is a little more complicated to job-related out. Eachbit to represent 2 to the strength of a an adverse number. The lookslike, **

** first bit the mantissa = 0.5 2nd = 0.25 third = 0.125 4th = 0.0625 fifth = 0.03125 and so on The mantissa number worth we have actually is 0.78125, i beg your pardon in binaryis **

**11001000000000000000000(0.5 + 0.25 + 0.03125) How-ever, to make matters even an ext complicated, the mantissais normalized, by relocating the little bit patterns to the left (each shiftsubtracts one from the exponent value) it spins the first 1 dropsoff. **

**The resulting pattern is climate stored. **

**The mantissa currently becomes **

** 10010000000000000000000 and also the exponent is adjusted to come to be **

** 131 - 1 = 130 = "10000010" The final assembled format 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 complying with storage format ago 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 negative number with 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 bit which was shifted off as soon as themantissa was normalized ), hence the number is, **

** -1.5625 * 24 = -25.0 The numeric variety for floating point numbers using theIEEE-754 method, utilizing 32 bits, is **

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

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

**var fp_number : real; begin fp_number := 12.50; The example declares the change fp_number to it is in afloating- point type, hence thirty-two bits of storage storage areallocated to store its worth (as however undetermined). **

**Inside the main body of the program, after ~ the keyword begin**,the statement presented assigns the numeric worth 12.50 to the realvariable fp_number. This is tantamount to storing the bitcombinations 01000001010010000000000000000000 in the thirty-twobits of storage allocated to the change fp_number.

The benefits of storing floating allude numbers in this wayare,

multiplication is perform by adding exponents and also mantissa"s division is performed by subtracting exponents and also mantissa"s that is easy to compare 2 numbers to view which is the higher or lesser large number arrays are stored using relatively few bitsThe disadvantages of the storage layout are,

errors are produced by relocating the mantissa bits conversion backwards and also forwards takes time