l>Introduction, bits, bytes, BCD, ASCII, characters, strings, integers and also floating point

*

Part 1

Reference Books:

Program architecture : p Juliff IBM Microcomputer Assembly Language : J Godfrey Programmers craft : R Weiland Data storage in a computer : CIT Microcomputer Software design : S Campbell

DATA STRUCTURESJust as learning to architecture programs is important, so is theunderstanding that the correct format and also usage the data. Allprograms usage some type of data. To architecture programs i m sorry workcorrectly, a great understanding of how data is structured will berequired.

This module introduces you come the various develops of data usedby programs. We shall investigate exactly how the data is stored,accessed and its usual usage in ~ programs.

A computer stores info in Binary format. Binary is anumber system which supplies BITS to keep data.

BITSA little is the smallest aspect of details used by a computer.A little holds one of TWO feasible values,




You are watching: How many bytes is one character

Value Meaning
0 OFF
1 ON

A little bit which is off is also considered to it is in FALSE or not SET;a little which is ~ above is also considered to be TRUE or SET.

Because a solitary bit deserve to only save two values, bits arecombined together into huge units in order to hold a greaterrange the values.

NIBBLEA nibble is a team of 4 bits. This offers 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 that bits, to determinewhich little bit of the group has the least value, and which bit has actually themost or best value.

The Least far-ranging Bit and also The most Sigificant BitThis is reputed to be little bit 0, and also is always drawn at the extremeright. The Most far-ranging bit is always shown top top the extremeleft, and also is the little bit with the biggest value.

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

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

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

BYTESBytes room a group of 8 bits. This comprises 2 nibbles, asshown below.

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

0 to 255 -127 to +128

Binary Coded Decimal Binary password decimal number (0-9) are stood for using four bits.The precious combinations that bits and their respective values room


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 combine 1010 to 1111 space invalid and also are notused.

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

If two BCD digits are stored per byte, its dubbed PackedBCD. This wake up in data transmission whereby numbers space beingtransmitted over a communications link. Packed BCD reduces theamount that time invested transmitting the numbers, together each data bytetransmitted results in the sending out of two 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 upper nibble holds the value 5, whilst the lower nibbleholds the value 6.

Status and Boolean VariablesBOOLEAN variables use a solitary bit to hold their value, therefore canonly assume among two feasible states. This is either 0(considered to it is in FALSE), or 1 (considered to be TRUE).

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

When a team of bits room grouped with each other to type a limitedrange of values, this is known as a STATUS variable.

Consider the case in a regimen where we should keep track ofthe number of minutes a phone line is liven for (within thelimited selection of 0 to 60). This walk not call for the use of afull integer, so part programming languages allow you to specifythe number of bits used to allocate come variables v limitedranges.

The benefit of this approach, is that the storage room ofstatus variables have the right to be combined together into a solitary 16 or 32bits, resulting in a conserving of space.

Consider where a computer system allocates 16 bits of storage perstatus variable. If we had actually three condition variables, the spaceconsumed would certainly be 48 bits. BUT, if every the standing variables couldbe merged and fitted right into a solitary 16 bits that storage, us couldsave 32 bits that memory. This is an extremely important in real-timesystems wherein memory space is at a premium.

Consider the adhering to diagram, i beg your pardon illustrates the packingof boolean and also status variables together right 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) | +------------------- minutes (bits 2-4) +----------------------- extension diverted/TRUE/FALSE

The American conventional Code for details InterchangeASCII is a computer system code which uses 128 different encodingcombinations that a team of seven bits (27 = 128) come represent,

personalities A come Z, both upper and lower case distinct characters, number 0 to 9 special regulate codes used for device control

Lets currently look in ~ the encoding method. The table below showsthe bit combinations required 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: What Is The Decimal Equivalent Of 5 8 As A Decimal? What Is 5/8 As A Decimal

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

Control codes are provided in communications and also printers. Theymay be generated from an ASCII keyboard by holding under the CTRL(control) crucial and pushing another an essential (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 wire is represented by the byte sequence

48 65 6C 6C 6F 2E

CHARACTERSCharacters space non-numeric symbols used to convey language andmeaning. In English, they are combined with other personalities toform words. Examples of personalities are;

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 A B C D E F G H ns 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 typically stores characters using the ASCIIcode. Every character is stored utilizing eight bits the information,giving a total variety of 256 different characters (2**8 = 256).

In the high level language Pascal, characters are identified andused together follows,

var plus_symbol : char; start plus_symbol := "+"; Variables provided in a Pascal regime are asserted after thekeyword var. The above example declares the change plus_symbolto it is in a personality type, thus eight bits of storage storage areallocated to store its worth (as however undetermined).

Inside the key body the the program, after ~ the keyword begin,the statement shown assigns the price + to the charactervariable plus_symbol. This is tantamount to storing theASCII value 2B hexadecimal in the eight bits of memory allocatedto the variable plus_symbol.

TEXT STRINGSText strings room a sequence of personalities (ie, words or multi-character symbols). Every character is save on computer one ~ the other,each occupying eight bits of memory storage.

The message string Hello would certainly be stored as follows

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

var text_message : string<22>; start text_message := "Welcome to message strings"; The above example declares the variable text_message to it is in astring form of up to 22 characters long (but no more!). Eightbits of storage storage room allocated to save each character inthe cable (a complete of 22 bytes), v the worth in every byte asyet undetermined.

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

INTEGERS Numeric information cannot successfully 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 complicated to call if the number was positive or negative(though we could precede it with the character + or -).

A an ext efficient means of save on computer numeric details is to usea different 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 worth in Binary |+---+--------------------------------------------+ S = Sign bit Integers store entirety numbers only! They do not containfractional parts. Think about the instances below,

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

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

Example store the worth +263 together an creature value. 1) The sign little is 0. 2) The decimal worth +263 is 100000111 in binary. Therefore the warehouse in memory of the creature +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 utilizing thetwo"s complement format.

In Pascal, integers room defined and used as follows,

var whole_number : integer; begin whole_number := 1267; The example declares the variable whole_number to be aninteger type, for this reason sixteen bits of storage storage room allocatedto store its worth (as however undetermined).

Inside the main body of the program, ~ the keyword begin,the statement presented assigns the numeric worth 1267 to the integervariable whole_number. This is equivalent to storing thebit combination 0000010011110011 in the sixteen bits the memoryallocated to the change whole_number.

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

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

FLOATING point NUMBERSThere are two difficulties with integers; they cannot expressfractions, and the range of the number is restricted to the numberof bits used. An efficient method of storing fractions is called thefloating allude method, i beg your pardon involves splitting the fraction intotwo parts, one exponent and a mantissa.

The exponent to represent a value elevated to the power of 2.

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

Consider the number

12.50 The number is an initial converted into the layout

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

The computer industry agreed ~ above a typical for the storageof floating allude numbers. The is dubbed the IEEE 754 standard,and uses 32 bits of memory (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 bit The sign bit is 1 because that a an unfavorable mantissa, and also 0 because that apositive mantissa.

The exponent supplies a predisposition of 127.

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

Working out the FP little bit patternsThe number we have actually is

12.5 which 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 fraction is the mantissa value, the number ofdivisions is the exponent value.

thus our values currently are,

0.78125 * 24 The exponent bit pattern is stored using an excess of 127.This way that this value is included to the exponent as soon as storing(and subtracted when removing).

The exponent bit pattern to keep is,

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

The mantissa is a little more facility to work out. Eachbit represents 2 come the strength of a an adverse number. It lookslike,

1st bit of mantissa = 0.5 second = 0.25 3rd = 0.125 4th = 0.0625 5th = 0.03125 etc The mantissa number value we have is 0.78125, i beg your pardon in binaryis

11001000000000000000000(0.5 + 0.25 + 0.03125) How-ever, to do matters even more complicated, the mantissais normalized, by relocating the bit patterns come the left (each shiftsubtracts one from the exponent value) it rotates the an initial 1 dropsoff.

The resulting sample is climate stored.

The mantissa currently becomes

10010000000000000000000 and also the exponent is changed to end up being

131 - 1 = 130 = "10000010" The last 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 currently lets convert the complying with storage format back 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 through an exponent value of,

131 - 127 = 4 and also a mantissa value of,

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

-1.5625 * 24 = -25.0 The numeric range for floating point numbers using theIEEE-754 method, using 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 allude numbers are defined and used asfollows,

var fp_number : real; begin fp_number := 12.50; The example declares the change fp_number to be afloating- point type, thus thirty-two bits of memory storage areallocated to save its worth (as yet undetermined).

Inside the key body of the program, after ~ the keyword begin,the statement displayed 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 variable fp_number.

The advantages of save on computer floating point numbers in this wayare,

multiplication is performed by adding exponents and mantissa"s department is performed by subtracting exponents and mantissa"s it is simple to compare 2 numbers to view which is the higher or lesser huge number arrays are stored utilizing relatively few bits

The disadvantages of the storage style are,

errors are produced by moving the mantissa bits counter backwards and forwards takes time

*