ics124 session 3 data representation
DESCRIPTION
ICS124 Session 3 Data Representation. 1. Review QUIZ. 1) The most powerful computers are: a) super PCsc)workstations b) supermainframesd) supercomputers 2) Perform the following conversions: 235 10 -> binary 873 10 -> hexadecimal 87 10 -> octal 1F34 16 -> binary - PowerPoint PPT PresentationTRANSCRIPT
ICS124
Session 3
Data Representation
1
Review QUIZ
1) The most powerful computers are:a) super PCs c)workstationsb) supermainframes d) supercomputers
2) Perform the following conversions:
23510
-> binary
87310
-> hexadecimal
8710
-> octal
1F3416
-> binary
256278 -> hexadecimal
2
Review QUIZ
1) The most powerful computers are:a) super PCs c)workstationsb) supermainframes d) supercomputers
2) Perform the following conversions:
23510
-> binary = 111010112
87310
-> hexadecimal = 36916
8710
-> octal = 1278
1F3416
-> binary = 0001-1111-0011-01002
256278 -> hexadecimal = 2B97
16
3
Objectives:By the end of this session, the student will be able to:Add two binary numbers together correctlyList two means to represent signed binary numbersConstruct signed binary numbers based on the two representationsShow an alternative way to represent subtraction of two numbersPerform binary subtraction through the use of twos complementList the three components of a floating-point numberDefine the criteria for Normalized Format when expressing a floating point numberReport on the Normalized Format criteria that has not been met when looking at a floating point numberCategorize the various numeric data types of the C languageAppreciate that the C language has multiple ways to represent numbersList 3 coding schemes used by computersApply the coding scheme tables to convert between characters and bit stringsDefine the term 'collating sequence' in relation to the coding schemesPredict the outcome of sorting data using the coding schemesDescribe the advantage of using Packed Decimal to store numbersConvert decimal numbers to signed Packed Decimal format
4
Binary Math
Binary mathThis section will introduce you to addition and subtraction of binary numbers.
AdditionRemember how we add in base-10:
1 1 <--- carry
297+194------- 491
In binary we only have four possible results:0
2 + 0
2 = 0
2
12 + 0
2 = 1
2
12 + 1
2 = 10
2 (this is were we carry the 1
2)
12 + 1
2 + 1
2 = 11
2 (if we had carried a one, we will need to again)
5
Binary Math
Addition, continued0
2 + 0
2 = 0
2
12 + 0
2 = 1
2
12 + 1
2 = 10
2 (this is were we carry the 1
2)
12 + 1
2 + 1
2 = 11
2 (if we had carried a one, we will need to again)
On a small scale, add these two binary numbers together:
1
0110+0100-------- 1010
If we convert these to decimal, we see that we are correct: 0110
2 is 6
10
01002 is 4
10
10102 is 10
10
6
Binary Math
Addition, continued0
2 + 0
2 = 0
2
12 + 0
2 = 1
2
12 + 1
2 = 10
2 (this is were we carry the 1
2)
12 + 1
2 + 1
2 = 11
2 (if we had carried a one, we will need to again)
On a small scale, add these two binary numbers together:
1 1
0110+0111-------- 1101
If we convert these to decimal, we see that we are correct: 0110
2 is 6
10
01112 is 7
10
11012 is 13
10
7
Binary Math
Example0
2 + 0
2 = 0
2
12 + 0
2 = 1
2
12 + 1
2 = 10
2 (this is were we carry the 1
2)
12 + 1
2 + 1
2 = 11
2 (if we had carried a one, we will need to again)
Perform this calculation: 11012 + 10111
2
Prove that the calculation is correct by converting all binary numbers to decimal.
8
Binary Math
Example0
2 + 0
2 = 0
2
12 + 0
2 = 1
2
12 + 1
2 = 10
2 (this is were we carry the 1
2)
12 + 1
2 + 1
2 = 11
2 (if we had carried a one, we will need to again)
Perform this calculation: 11012 + 10111
2
10111 1x24 + 0x23 + 1x22 + 1x21 + 1x20 = 23 1101 1x23 + 1x22 + 0x21 + 1x20 = 13 -----100100 1x25 + 0x24 + 0x23 + 1x22 + 0x21 + 0x20 = 36
9
Binary Math
SubtractionFor subtraction, we are used to seeing this form in base-10:
297 - 194 = 103
The problem with subtraction is that is gets messy with borrowing. The following are simple subtractions:
02 - 0
2 = 0
2
12 - 1
2 = 0
2
12 - 0
2 = 1
2
We have to borrow if we see 02 - 1
2.
10
Binary Math
Subtraction, continuedImagine this binary subtraction:
1101- 1001------ 0100
How about: 1000- 0001------ 0111
Is there an easier way?
11
Binary Math, continued
Signed and unsigned numbersSo far the numbers we have been dealing with are all positive integers. However, there exists such things as negative numbers, as in 297 + (-194) = 103
Unfortunately, computers are aware of only two states, on and off. These states are used to represent the bits in the binary number system. There is no third state to represent negative bits.
A means to differentiate between positive numbers and negative numbers is required.
There are two schemes used to differentiate between positive and negative numbers:
Sign and Magnitude Twos complement
In this class when working with signed binary numbers, work in multiples of eight-bits. You may discard overflow bits.
12
Binary Math, continued
Sign and magnitudeThe simplest means to differentiate between positive and negative numbers is to reserve one of the bits of a binary number to indicate sign. The most significant bit has been chosen for this purpose. This leaves one less bit to represent the number- for example 7 bits or 15 bits.
IF the sign bit is '0' THEN the number is positiveIF the sign bit is '1' THEN the number is negative
For example:
0101 11012 = +93
10
1101 11012 = -93
10
Since (+93) +(-93) = 0then 01011101
2 + 11011101
2 should be 00000000
2
Try it.
13
Binary Math, continued
Sign and magnitude, continued
Since (+93) +(-93) = 0then 010111012 + 11011101 should be 00000000
01011101 +11011101 --------- (1)01111010
Remember to ignore the overflow bit.
Since the sign-bit is in the MSB position and we are using only 7 bits to represent the number, the result is:01111010
2
= +12210
Using this technique is not very effective. 14
Binary Math, continued
Twos complementTwos complement, or 2s complement, is very similar to the scheme that uses just a sign bit. However, as we shall see when we perform subtraction, this scheme is better.
To calculate the 2s complement of a number:flip the bits (1 -> 0, 0 -> 1) this stage is also referred to as one's complementadd 1
For example, 01011101
2 becomes
101000102
<--- bits flipped+ 1
2
--------------- 10100011
2
So 010111012
is +9310
, and
101000112
is -9310
15
Binary Math, continued
Twos complement, continuedTo take a negative number in 2s complement and convert into a positive number, perform the 2s complement operation again.
For example, 10100011
2 (-93
10)becomes
010111002
+ 12
----------- 01011101
2
So 010111012 is +93
10, and
101000112 is -93
10
16
Binary Math, continued
Twos complement, continuedIf we wish to perform 93
10 - 93
10, we could instead perform 93
10 + (-93
10). In
binary it would be:
010111012
+ 101000112
------------(1)00000000
2
The overflow 12 is ignored. This is also what happens in the CPU, and it knows
when to ignore the overflow 12 bit as well.
17
Binary Math, continued
Twos complement, continuedWhat is the result of 42
10 - 53
10 (perform the calculation in binary):
?
18
Binary math, continued
Twos complement, continuedWhat is the result of 42
10 - 53
10 (perform the calculation in binary):
4210 = 42 / 2 = 21 R 0 53
10 = 53 / 2 = 26 R 1
21 / 2 = 10 R 1 26 / 2 = 13 R 0 10 / 2 = 5 R 0 13 / 2 = 6 R 1 5 / 2 = 2 R 1 6 / 2 = 3 R 0 2 / 2 = 1 R 0 3 / 2 = 1 R 1 1 / 2 = 0 R 1 1 / 2 = 0 R 1 = 0010 1010
2 = 0011 0101
2
5310 in 2s complement: 42
10 + (-53
10):
001101012 ->11001010 00101010+ 1 + 11001011------------- -----------
11001011 11110101 -> 00001010 + 1 --------- 00001011 = -11
1019
Binary Math, continued
PracticePerform the following calculations.
Convert to binary first, if required Assume a 16-bit ALU Assume a 2s complement number if the MSB of the 16-bit ALU is 1
2
Convert answers back to their original base
1001110112 + 11011001
2
9AC16
+ 8CA16
7348 + 6453
8
FEED16
- BAD16
20
Binary Math, continued
PracticePerform the following calculations.
Convert to binary first, if required Assume a 16-bit ALU Assume a 2s complement number if the MSB of the 16-bit ALU is 1
2
Convert answers back to their original base
1001110112 + 11011001
2
0000 0001 0011 1011+0000 0000 1101 1001-------------------- 0000 0010 0001 0100
21
Binary Math, continued
PracticePerform the following calculations.
Convert to binary first, if required Assume a 16-bit ALU Assume a 2s complement number if the MSB of the 16-bit ALU is 1
2
Convert answers back to their original base
9AC16 + 8CA
16
0000 1001 1010 1100 (9AC16)
+0000 1000 1100 1010 (8CA16)
-------------------- 0001 0010 0111 0110 = 1276
16
22
Binary Math, continued
PracticePerform the following calculations.
Convert to binary first, if required Assume a 16-bit ALU Assume a 2s complement number if the MSB of the 16-bit ALU is 1
2
Convert answers back to their original base
7348 + 6453
8
0 000 000 111 011 100 (7348)
+0 000 110 100 101 011 (64538)
---------------------- 0 000 111 100 000 111 = 7407
8
23
Binary Math, continued
PracticePerform the following calculations.
Convert to binary first, if required Assume a 16-bit ALU Assume a 2s complement number if the MSB of the 16-bit ALU is 1
2
Convert answers back to their original base
FEED16 - BAD
16
BAD16 in 2s complement: 0000 1011 1010 1101
1111 0100 0101 0010 + 1 -------------------- 1111 0100 0101 0011
1111 1110 1110 1101 (FEED16)
+1111 0100 0101 0011 (2s comp of BAD16)
-------------------- 1111 0011 0100 0000 = F340
1624
Floating Point Numbers
25
Floating Point Numbers
Floating point numbersThe numbers that we have been dealing with are all integers with limited precision. For example, a 16-bit binary number can store values between -32768 and +32767 using 2s complement.
We have a need to represent numbers that are either very small (such as the diameter of a virus) or very large (such as the diameter of the solar system).
Floating point numbers are how we represent these numbers.
RepresentationA way to represent numbers is to use three components to describe the number:
Base Mantissa Exponent
26
Floating Point Numbers, continued
Representation, continuedThe general form for representing a floating point number is
M x Be
where 'M' is the mantissa, 'B' is the base and 'e' is the exponent.
An example of a floating point number in this form is: 0.523x103 (which is 523)
BaseThe base is the numbering system that is being used, such as decimal (10) or binary (2).
27
Floating Point Numbers, continued
MantissaMantissa is the numeric portion of the floating point number being represented. It will be:
B-1 <= | M | < 1
This is referred to as Normalized Format
Looking at the previous example:0.523x103
we see that the mantissa is < 1, and greater than or equal to 10-1 (which is 0.1).
What all this boils down to is no numbers are to the left of the decimal point, and the first number to the right of the decimal point is not a zero.
Both of these are invalid mantissas:7.003
0.084
28
Floating Point Numbers, continued
Mantissa, continuedSince we are dealing with values to the right of the 'radix point' (commonly called a decimal point in the decimal numbering system), the digit exponents are negative:
In Decimal:10-1, 10-2, 10-3, 10-4, 10-5, 10-6...= 1/10, 1/100, 1/1000, 1/10000, 1/100000= 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001....
So, similar to what we have seen:0.10236= 1x10-1 + 0x10-2 + 2x10-3 + 3x10-4 + 6x10-5
ExponentThe exponent is applied to the base, and then the mantissa is multiplied by this value:0.10236 x 104
=1023.6
29
Floating Point Numbers, continued
Storing a binary floating-point numberThe same components are used:
BaseExponentMantissa
There are specific representations defined by IEEE (Institute of Electrical and Electronics Engineers www.ieee.org) for the storage of floating point numbers.
For single precision, 32 bits are used as follows:
30
Floating Point Numbers, continued
BaseSince are dealing with a binary machine, the base is always 2. There is no need to store it in memory.
MantissaThe mantissa is stored in sign and magnitude format and is normalized, HOWEVER, there is a slight variation regarding normalization. The binary mantissa is in the range of:1.00000000000000000000000 to1.11111111111111111111111
1.0 <= | M | < 2
Since the mantissa ALWAYS starts with a '1', the leading 1 is never stored, it is assumed to be there.
Therefore, 1.00011111111111111111101would be stored as 00011111111111111111101
This is the normalized format for the storage of floating point binary numbers.31
Floating Point Numbers, continued
Mantissa, continuedSince we are dealing with values to the right of the 'radix point' (commonly called a decimal point in the decimal numbering system), the digit exponents are negative:
In Decimal:10-1, 10-2, 10-3, 10-4, 10-5, 10-6...= 1/10, 1/100, 1/1000, 1/10000, 1/100000= 0.1, 0.01, 0.001, 0.0001, 0.00001, 0.000001....
In Binary2-1, 2-2, 2-3, 2-4, 2-5, 2-6...= 1/ 2 1/ 4 1/8 1/16 1/32 1/64....= 0.5, 0.25, 0.125, 0.0625, 0.03125, 0.015625...
therefore 1.12 = 1x20 + 1x2-1 = 1
10 + 1/ 2
10 = 3/2
10
32
Floating Point Numbers, continued
ExponentThe exponent is stored in 'Excess 127' format. To get the exponent, you subtract
127 from the stored value.
Therefore, if the value stored is 120, the exponent would be -7
There are two 'special' cases for the exponent: 0 - represents 'Exactly zero' (as opposed to a number that looks like zero
because it has lost its precision) 255 - represents infinityA portion of the excess-127 table:00000000 0 - exactly 0...01111101 125 - -201111110 126 - -101111111 127 - 010000000 128 - +110000001 129 - +2...11111111 255 - infinity
33
Floating Point Numbers, continued
Layout of floating point numberThe layout is as follows:Sign bit - 1 bitExponent - 8 bitsMantissa - 23 bits ======
32 bits
Seee-eeee-eMMM-MMMM-MMMM-MMMM-MMMM-MMMM0100-0000-0000-0000-0000-0000-0000-0000 = +2
10
34
Floating Point Numbers, continued
Layout of floating point number, continued
Seee-eeee-eMMM-MMMM-MMMM-MMMM-MMMM-MMMM1100-0011-1001-0110-0000-0000-0000-0000
Sign is negativeExponent = 10000111 = 135 135 - 127 = 8 represents 28
Mantissa = 1.001011 = 1 + 1/8 + 1/32 + 1/64 = 75/64
-75/6410 x 28 = -300.00
10
35
Numbers in the C Language
36
Numbers in C
PurposeAlthough we have not begun to talk about programming languages yet, we can appreciate the limits of a computer, based on the discussions of data representation thus far.
BackgroundWhen a programmer wishes to manipulate data in a program, they will refer to a symbolic name when they need to perform some action on that data.
A way of thinking of a symbolic name is to consider an application form. On this application form is a question about your age. It shows up on the form like:
Applicant's Age
The box is where you enter the data (your age), and the words beside the box is a label or symbolic name.
The programmer, may call this variable in their program applicantsAge
37
Numbers in C, continued
Background, continuedWhen a C programmer needs a symbolic name, they make up the name, but must tell the computer what type of data the symbolic name will represent.
The data types for C are: char short int int long int float double
38
Numbers in C, continued
char data typeA char is one byte, and is used to represent characters.
It can store numbers between 0 and 255 (where each number represents a character on the keyboard, plus other special characters).
39
Numbers in C, continued
short int data typeThe short int is an integer.
It can store numbers between -32768 and 32767
40
Numbers in C, continued
int data typeThe int is slightly larger
It can store numbers between -2,147,483,648 to 2,147,483,647
41
Numbers in C, continued
long int data typeThe long int is larger again
It can store numbers between -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
42
Numbers in C, continued
float data typeThe float is where the ability to store non-integers (real numbers) begins (single precision- 32 bits).
It can store numbers between 0.11754943508222875x10-39 to 0.34028234663852886x10+39
43
Numbers in C, continued
double data typeThe double is larger (double precision- 64 bits)
It can store numbers between 0.22250738585072014x10-309 to 0.17976931348623158x10+309
44
Coding Schemes
45
Coding Schemes
BackgroundIn our discussions of data representation, we have been dealing with pure binary numbers. However, we as humans, work with more than numbers. We need to represent words and symbols and ideas that are more than simply numbers.
For example, the binary stream 100100011001011101100110110011011112
is also used to represent the word 'Hello'.
Another way to think of this is consider a payroll program. Some of the data is pure numbers such as pay rate and hours worked. Other data is the Social Insurance Number (S.I.N.) and name of the employee. The SIN and name are not used as numbers as there are no meaningful calculations performed on them.
What is the significance of :(John Doe + 3) / 5 ?
A means to represent more than simply numbers, is possible through a coding scheme where simple numbers are used to represent letters of a word or symbols. Ideas meaningful to people can be constructed from this scheme.
46
Coding Schemes, continued
Early coding schemesTwo early coding schemes will be looked at. One pre-dates computers, the other is an early zoned coding scheme:
Morse Code 6-bit Binary Coded Decimal
Morse CodeAn early coding scheme use to represent letters and numbers is the Morse Code. This scheme used two symbols, a dot and a dash in various combinations to represent letters. For example, here is a portion of the Morse Code:
http://tronweb.super-nova.co.jp/characcodehist.html
47
Coding Schemes, continued
6-bit Binary Coded DecimalThe problem with Morse Code is that there are a variable number of dots and dashes to represent the letters and numbers.
Binary Coded Decimal (BCD), is used to represent each digit of a decimal number. For input and output operations, it allows the device to treat each character as an independent entity. The following is how decimal numbers are stored in BCD format:
Decimal Binary Decimal Binary0 0000 5 01011 0001 6 01102 0010 7 01113 0011 8 10004 0100 9 1001
It should be no surprise that these binary numbers are straight conversions of the decimal number. When entering a value of 123
10, instead of entering
011110112, we enter 000100100011
2.
48
Coding Schemes, continued
6-bit Binary Coded Decimal, continuedDecimal Binary Decimal Binary0 0000 5 01011 0001 6 01102 0010 7 01113 0011 8 10004 0100 9 1001
To represent values other than numbers, two zone bits are added to the beginning of the codes above, give the 6-bit BCD Code.
Zone 00 - Numbers 0 -9Zone 01 - Letters S - ZZone 10 - Letters J - RZone 11 - Letters A - I
The 6-bit BCD code table follows:
49
Coding Schemes, continued
6-bit Binary Coded Decimal, continuedCharacter Code Character CodeA 11 0001 S 01 0010B 11 0010 T 01 0011C 11 0011 U 01 0100D 11 0100 V 01 0101E 11 0101 W 01 0110F 11 0110 X 01 0111G 11 0111 Y 01 1000H 11 1000 Z 01 1001I 11 1001
0 00 1010J 10 0001 1 00 0001K 10 0010 2 00 0010L 10 0011 3 00 0011M 10 0100 4 00 0100N 10 0101 5 00 0101O 10 0110 6 00 0110P 10 0111 7 00 0111Q 10 1000 8 00 1000R 10 1001 9 00 1001
50
Coding Schemes, continued
Modern coding schemesThe problem with 6-bit BCD is that there are more characters that need to be represented than can be fit into this scheme. Although symbols can be fit into the unused codes, lower-case letters are completely missed.
There are two standard coding schemes used today that resolve this problem: ASCII EBCDIC
There is an advantage to using a standard coding scheme. Regardless of the computer system being used, you will be able to send data to another computer system that uses the same standard, and it will be identical.
51
Coding Schemes, continued
ASCIIASCII (pronounced ask-ee) is an acronym for American Standard Code for Information Interchange.
It is found everywhere, except IBM mainframes.
The ASCII code is a 7-bit code, and therefore can represent 128 possible characters.
Unlike 6-bit BCD code, the order of the characters makes more sense. They are in sequence:6-bit Binary: 1234567890STUVWXYZJKLMNOPQRABCDEFGHIASCII: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ
This is an important feature when comparing words alphabetically. The 6-bit BCD word ZEBRA would come before ALPHA.
The ASCII code table follows:
52
Coding Schemes, continued
ASCII, continued
The bit pattern for the letter 'Z' would be 1011010
Bit Positions 6543210 000 001 010 011 100 101 110 1110000 NULL DLE SPACE 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EOT DC4 $ 4 D T d t0101 ENQ NAK % 5 E U e u0110 ACK SYN & 6 F V f v0111 BEL ETB ' 7 G W g w1000 BS CAN ( 8 H X h x1001 HT EM ) 9 I Y I y1010 LF SUB * : J Z j z1011 VT ESC + ; K [ k {1100 FF FS , < L \ l |1101 CR GS - = M ] m }1110 SOH RS . > N ^ n ~1111 SI US / ? O _ o DEL
53
Coding Schemes, continued
ASCII, continued
The bit pattern for the word ‘Hello' would be 10010001100101110110011011001101111
Bit Positions 6543210 000 001 010 011 100 101 110 1110000 NULL DLE SPACE 0 @ P ` p0001 SOH DC1 ! 1 A Q a q0010 STX DC2 " 2 B R b r0011 ETX DC3 # 3 C S c s0100 EOT DC4 $ 4 D T d t0101 ENQ NAK % 5 E U e u0110 ACK SYN & 6 F V f v0111 BEL ETB ' 7 G W g w1000 BS CAN ( 8 H X h x1001 HT EM ) 9 I Y I y1010 LF SUB * : J Z j z1011 VT ESC + ; K [ k {1100 FF FS , < L \ l |1101 CR GS - = M ] m }1110 SOH RS . > N ^ n ~1111 SI US / ? O _ o DEL
54
Coding Schemes, continued
ASCII, continuedA very important point to keep in mind is that the ASCII character for '0' (zero) is actually a number 0110000
2 (48
10) used to represent the character on the
keyboard or on the monitor.
It is very important to maintain the context of the number in mind. Know when 0110000
2 is 48
10 and when it is '0'.
Because the ASCII codes are numbers, there are some conversions to keep in mind.
55
Coding Schemes, continued
ASCII ConversionsA common conversion in computers is to convert upper-case letters (ABC...) to lower-case letters (abc..) and back.
By referring to the ASCII table, we see that 'A' and 'a' are separated by 3210
other characters. So to...
convert from upper-case to lower-case, add 3210
convert from lower-case to upper case subtract 3210
When we look at the ASCII numbers, we see that they all start with 011xxxx. So to...
convert from ASCII to binary number subtract 4810
convert from binary number (00002 - 1001
2), to ASCII add 48
10
56
Coding Schemes, continued
ASCII-8An expanded ASCII character set has been devised to allow more characters. Instead of a 7-bit code, an 8-bit code is used.
The characters added weregraphics charactersaccented characters, andspecial symbols.
The graphics characters were fixed symbols that could be used to render rudimentary line drawings.
The accented characters where applicable to French, German and Spanish languages.
The special symbols included some Greek characters for math applications as well as currency (Pounds-sterling, Yen).
57
Coding Schemes, continued
EBCDICEBCDIC (pronounced eb-see-dick) is an acronym for Extended Binary Coded Decimal Interchange Code.
From its name, we can see that it is an enhancement of the 6-bit BCD scheme.
The EBCDIC scheme was developed by IBM.
Unlike ASCII, EBCDIC began as an 8-bit scheme, providing 256 possible characters.
Portions of the EBCDIC table follow:
58
Coding Schemes, continued
EBCDICBit Positions 76543210 0000… 0110 0111 1000 1001 1010… 1100 1101 1110 11110000 NUL _ 00001 / a j A J 10010 b k s B K S 20011 c l t C L T 30100 PF d m u D M U 40101 HT e n v E N V 50110 LC f o w F O W 60111 DEL g p x G P X 71000 h q y H Q Y 81001 i r z I R Z 91010 : 1011 , #1100 % @1101 - '1110 > =1111 ? "
59
Coding Schemes, continued
Collating sequenceThe collating sequence of a coding scheme defines the order that the characters come in. For example, the collating sequence of the alphabet is:
AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz
This collating sequence is used to place words into order, such as in a dictionary.'Alpha' comes before 'Zebra', and 'Alpha' comes before 'alpha'.
ASCII collating sequenceThe collating sequence for ASCII is:blank ! " # $ % & ' ( ) * + , - . /0...9: ; < = > ? @A...Z[ \ ] ^ _ `a...z{ | } ~
In this example 'Alpha' comes before 'alpha', and '123' comes before 'Alpha'60
Coding Schemes, continued
EBCDIC collating sequenceThe collating sequence for EBCDIC is:blank . < ( + | & ! $ * ) ; - / , % _ > ? : # @ ` = "a...zA...Z0...9
In this example 'alpha' comes before 'Alpha', and 'alpha' comes before '123'
ASCII versus EBCDIC collating sequencesBy looking at the two collating sequences, we can see that a program that sorts data on an ASCII-based computer system will produce different results if it is run on an EBCDIC-based computer system.
Therefore, programs written to run on an ASCII-based computer system may behave completely different if run on an EBCDIC-based computer system.
61
Packed Decimal
62
Packed Decimal
Packed DecimalPacked decimal is an older form of storing integers that is still in use.
It is similar to zoned coding schemes, however it uses less memory than 6bit-BCD, ASCII or EBCDIC
How is the number 57398 represented in:6-bit BCD?ASCII?EBCDIC?
63
Packed Decimal, continued
Packed DecimalHow is the number 57398 represented in:6-bit BCD = 000101 000111 000011 001001 001000ASCII? = 00110101 00110111 00110011 00111001 00111000EBCDIC? = 11110101 11110111 11110011 11111001 11111000
In Packed decimal each nibble is used to represent a digit between 0 and 9. The right-most nibble stores the sign of the number. A leading zero may be required when representing the number.
The sign nibble is: 1100 for positive numbers 1101 for negative numbers
How would 57398 be represented in packed decimal?
64
Packed Decimal, continued
Packed DecimalHow is the number 57398 represented in:6-bit BCD = 000101 000111 000011 001001 001000ASCII? = 00110101 00110111 00110011 00111001 00111000EBCDIC? = 11110101 11110111 11110011 11111001 11111000
In Packed decimal each nibble is used to represent a digit between 0 and 9. The right-most nibble stores the sign of the number. A leading zero may be required when representing the number.
The sign nibble is: 1100 for positive numbers 1101 for negative numbers
How would 57398 be represented in packed decimal?
01010111 00111001 10001100
65