Download presentation
Presentation is loading. Please wait.
Published byMervyn Tyler Modified over 9 years ago
1
Representing Data
2
Representing data u The basic unit of memory is the bit A transistor that can hold either high or low voltage Conceptually, a tiny container that can hold 1 or 0 All data is represented using 1’s and 0’s u How are integers represented? u How are colors represented? u How are strings represented?
3
Representing numbers
4
Weighted Positional Notation u Use the position of the symbol to indicate the value u By assigning each position the appropriate power of the base, we can get a unique representation of numbers in that base Decimal System (Base 10) Given a sequence of n digits d 0,d 1,…,d n-1 d n-1.10 n-1 + … + d 1.10 1 + d 0.10 0
5
Weighted Positional Notation u In general, given a sequence of n digits s 0,s 1,…,s n-1 and a base b, s n-1.b n-1 + … + s 1.b 1 + s 0.b 0 yields a unique integer N u s 0 is the least significant digit u s n-1 is the most significant digit u The most significant symbol can not be zero
6
Weighted Positional Notation u Any positive integer value can be used as the base for a weighted positional notation u For bases less than or equal to 10, a subset of the ten decimal digits can be used binary (base 2) octal (base 8) u For bases more than 10, new symbols will have to be introduced hexadecimal (base16) A=10, B=11, C=12, D=13, E=14, F=15
7
Weighted Positional Notation u A subscript is used to indicate the base of the number in typeset A number without a subscript is assumed to be base 10 Not an option while programming u In VB, hexadecimal representation begins with &H &H10 (= decimal 16) u So the following instructions are identical form.backcolor = &H13 form.backcolor = 19
8
Representations in Different Bases binary hexdecimalbinaryhexdecimal 000000100088 000111100199 0010221010A10 0011331011B11 0100441100C12 0101551101D13 0110661110E14 0111771111F15
9
Binary and Hexadecimal u Discriminating between two voltage levels is currently cheaper in digital circuitry than three or more, thus binary is the representation for computers u It is much easier for humans to work with hexadecimal representations Long strings of 1’s and 0’s are hard to remember u Binary to hexadecimal conversion is more direct than binary to decimal conversion Reason: 16 is a power of 2
10
Conversion to Decimal Given a sequence of base-r digits s n-1... s 1 s 0 convert the sequence into a decimal number N using: N = s n-1 *b n-1 + … + s 1 *b 1 + s 0 *b 0
11
Conversion to Decimal Convert 10 0110 2 to decimal N = 1*2 5 + 0*2 4 + 0*2 3 + 1*2 2 + 1*2 1 + 0*2 0 = 38 Convert 3b2 16 to decimal N = 3*16 2 + 11*16 1 + 2*16 0 = 946 Convert 370 8 to decimal N = 3*8 2 + 7*8 1 + 0*8 0 = 192 + 56 + 0 = 248
12
A Binary Exercise u The binary number 10001011 is identical to 139 base 10 u In the decimal, the number 139 can be written is interpreted as: 1 X 100 = 100 3 X 10 = 30 9 X 1 = + 9 Total 139 u In binary, the same procedure yields: 1 x 128 = 128 0 x 64 = 0 0 x 32 = 0 0 x 16 = 0 1 x 8 = 8 0 x 4 = 0 1 x 2 = 2 1 x 1 = + 1 Total = 139
13
A Hexadecimal Exercise Binary Decimal: 10001011 1 x 128 = 128 0 x 64 = 0 0 x 32 = 0 0 x 16 = 0 1 x 8 = 8 0 x 4 = 0 1 x 2 = 2 1 x 1 = + 1 Total = 139 Hexadecimal Decimal: 8B 8 x 16 = 128 B or 11 x 1 = +11 Total = 139
14
Converting Binary to Hexadecimal u Converting binary to hexadecimal is a simple exercise in pattern recognition Break the binary number into groups of 4 bits, starting from the right If necessary, pad the leftmost group with 0's until it is also 4 bits in length Replace each 4 bit grouping with a single hexadecimal character determined by the chart
15
Representations in Different Bases binary hexdecimalbinaryhexdecimal 000000100088 000111100199 0010221010A10 0011331011B11 0100441100C12 0101551101D13 0110661110E14 0111771111F15
16
Binary-Hex Conversion Example u Convert the binary number 1101010100101010011 to hexadecimal 1101010100101010011 0 6 A 9 5 3
17
Representing Colors and Strings
18
Specifying Visual Basic Colors u Two ways: By Color name Ex: “vbRed”, “vbGreen”, “vbBlue” Provides basic colors Must know the precise names allowed By Hexadecimal color value Ex: “&H00FF3A” Allows up to 16.7 million possibilities!
19
Color Theory u All colors are a combination of three primary colors Red Green Blue u Specify intensity of each primary color to create a unique color
20
Combining primary colors 256 Intensities 256 Intensities 256 Intensities Total possibilities = 256 3 or approximately 16.7 million colors!
21
Why 256 Intensities? u Computers operate on Base 2 u 1 bit can be either 0 or 1 0 is off, 1 is on u 1 byte consists of 8 bits Ex: 01011101 The possibilities are 2 8 or 0-255 u A byte is the smallest addressable unit of computer storage
22
Using hexadecimal for colors u Each primary color intensity is expressed as two hexadecimal digits u Possibilities are 0-255 u Ex: Convert 221 to Hexadecimal 221/16 = 13 Remainder 12 13 = D in Hexadecimal 12 = C in Hexadecimal 221 = &HDC In the properties window, VB displays all color codes with 8 hexadecimal digits &H000000DC
23
Expressing hexadecimal colors u Sample Color Value: &H00DC0F4A Prefix indicating a hexadecimal number The first byte codes the blue saturation The second byte codes the green saturation The third byte codes the red saturation
24
Color Intensity u 00 is the lowest intensity u FF is the highest intensity u What color is &H000000? u What color is &HFFFFFF?
25
Representing Text ASCII (American National Standards Institute ANSI) American Standard Code for Information Interchange ASCII code is an 8bit code for character representation. For example the code for H is 01001000, for e is 01100101 So the message “Hello.” can be coded as 01001000 01100101 01101100 01101100 01101111 00101110
26
Representing Text ASCII table (starting from #32)
27
ASCII Table u The ASCII table is appendix A of the text u You can find many examples of the ASCII table of characters online, for example http://www.physics.udel.edu/~watson/scen103/ascii.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.