Report

Numbers in Our Pockets GCNU 1025 Numbers Save the Day Numbers in our pockets • A fundamental use of numbers: counting Numbers in our pockets • How about banknotes? Numbers in our pockets • ID number for identifying/tracking banknotes Numbers in our pockets • ID number for identifying/tracking banknotes 1. Numbers for identification An ID (identification) number is a string of numbers that is used for identification. It enables us to recognize the object or person attach to that number. Examples: • Postal codes • Phone numbers • Country codes • Numbers in cheques Postal Codes • A post code (or post code, postcode, ZIP code) is a series of letters and/or numbers appended to a postal address (or a delivery route). • Different countries with different systems. • Postal codes allow us to recognize the geographical area to which the code refers. • ZIP code in the address of Harvard University: MA 02138 • Some more specific ZIP codes have 4 extra digits (“ZIP+4”) ZIP codes of US Chinese postal codes • 6 digits (e.g. 518053) • 4 levels: 51-8-0-53 – – – – First 2 digits: province/municipality/autonomous region 3rd digit: postal zone 4th digit: district Last 2 digits: local post office Phone numbers for identification Hong Kong telephone numbers • Which are fixed land line numbers? How can you tell? A. 2363 2767 B. 3411 2801 C. 5589 4120 D. 6583 2042 E. 7729 1502 F. 8320 1529 G. 9258 4981 Hong Kong telephone numbers • Number of a church: 2363 2767 • 363 xxxx: before 01/01/1995 • Where is the church? Kowloon? Hong Kong Island? New Territories? Outlying Islands? How can you tell? Hong Kong telephone numbers • Where is the church? Kowloon? Hong Kong Island? New Territories? Outlying Islands? How can you tell? • 363 2767: a number in Kowloon • 1970s: (3)63 2767 – First “3”: area code for Kowloon – 632767 was the actual number – No need to dial the area code if you are in Kowloon Hong Kong telephone numbers • The leading digits of a Hong Kong telephone number are partially related to the location of the telephone line Country codes • How can a friend of yours from the US call you? Can he/she just dial your number? • Need to dial 852 before the number (and probably also the number provided by the service provider) Numbers for identification • Why can’t a Hong Kong number be 99920842? • Can the country code of China be 85? • Example: 8526543210 – Interpretation #1: 852-6543210 (Hong Kong) – Interpretation #2: 85-26543210 (not Hong Kong) • Prefix property: – No phone number (country code) can be the prefix of another phone number (country code) Numbers in Cheques • Cheque number, routing/transit number for issuing bank/branch, account number Numbers in Our Pockets GCNU 1025 Numbers Save the Day 2. Numbers for error-checking Some identification numbers include error-checking features to enable us to check their validity. Examples: • HKID card numbers • Credit card numbers Warning: designed to detect errors rather than to prevent fraud. HKID card numbers • Some basics about HKID card numbers • Check digits of HKID card numbers Validity of Y123456(9) • Rule: every valid HKID number has a special property • Step 1 (of checking validity): • Step 2 (of checking validity): • Step 3 (of checking validity): is this “check sum” 286 divisible by 11? YES! The number is valid! Classwork 1: validity of HKID number Have a try checking your own HKID…. A missing digit of a valid HKID number • If Y123464(*) is valid, what is “*”? • Step 1: Y 1 2 3 4 6 4 * x 8 7 6 5 4 3 2 1 = 200 7 12 15 16 18 8 * • Step 2: – – – – Check sum = 276 + * (which is known to be divisible by 11) What should “*” be? Can “*” be 0-9? If Y123464(*) is valid, “*” has to be 10! Use “A” to represent 10 (recall the base 16 arithmetic) HKID card check digit • Weighted modulo 11 check: check digit appended to make check sum divisible by 11 • 0-9 or A (representing 10) • Using “A” for “10” is not uncommon in other numeral systems (compare: base 16 numbers such as “B1A”) HKID card check digit - Review • Weighted modulo 11 check: check digit appended to make check sum divisible by 11 • 0-9 or A (representing 10) • Using “A” for “10” is not uncommon in other numeral systems (compare: base 16 numbers such as “B1A”) HKID card check digit - Review http://www.cp.hk/articles/identity.asp Quote: Incidentally, the last character in brackets ( ) is actually not part of the HKID. It is a check digit which depends on the characters in the HKID, resulting between 0-9 or A. It is generated by a fairly simple formula, and is used to check for errors, because if you get one character wrong in the ID, then the check digit will be wrong. You can use our new online HKID check digit generator to calculate the check digit of any HKID - try it and see! Hours of fun for all the family. http://www.cp.hk/dbpub/idcheck.asp Place value: base 10 system • Every digit must be from 0-9 (e.g. 1985) • For a base 10 number “1985”: Digit Value of the position Actual value 1 1,000 (10x10x10) 1,000 9 100 (10x10) 900 8 10 (10) 80 5 1 5 Place value: base 16 system • Base 16: every digit must be from 0-15 10 11 12 13 14 15 A B C D E F • For a base 16 number “3A24”: Digit Value of the position Actual value 3 4096 (16x16x16) 12,288 A (10) 256 (16x16) 2,560 2 16 (16) 32 4 1 4 Other numeral systems Numeral system Digits from Base 10 0-9 Base 16 0-15 Base 60 0-59 Base 12 0-11 Base 2 0-1 Base 8 0-7 Duodecimal system Hexadecimal system Sexagesimal system Stems-and-branches Numeral systems Numeral system Uses Binary (base 2) Computers Octal (base 8) Used to be popular in Central America Duodecimal (base 12) 1 foot = 12 inches Hexadecimal (base 16) 1 pound = 16 ounces Sexagesimal (base 60) 1 minute = 60 seconds Number for error-checking: remarks • Not for fraudulence prevention – Schemes known to public – A counterfeit (i.e. a fake) could still have a valid number – Other schemes available for such purpose Numbers in Our Pockets GCNU 1025 Numbers Save the Day Credit card check scheme • Weighted modulo 10 check: check digit (i.e. last digit) appended to make check sum divisible by 10 • How to calculate the check sum? How are the digits weighted? Validity of 5424 7171 3312 0044 • Rule: every valid credit card number has a special property • Step 1 (of checking validity): • Step 2 (of checking validity): • Step 3 (of checking validity): Is this “check sum” 50 divisible by 10? YES! The number is valid! Credit card check scheme Luhn algorithm http://en.wikipedia.org/wiki/Luhn_algorithm See also “bank card numbers” http://en.wikipedia.org/wiki/Bank_card_number Classwork 2: validity of credit card number Why not try the credit cards in your own pocket? Numbers in Our Pockets GCNU 1025 Numbers Save the Day 3. Barcodes A 1D barcode is a series of dark bars and light spaces that represent characters/data. A scanning device is needed to pass over the bars and spaces to read the data. Examples: • UPC barcodes (1D) • QR codes (2D) Error-correcting feature of QR codes UPC (barcode) check scheme • A (one-dimensional) barcode represents data by varying the width and the spacing of parallel lines • Primary example: Universal Product Code (UPC) UPC (barcode): basic features • 12-digit • 1st digit: product category Prefix Category 0, 1, 6, 7 or 8 Ordinary products 2 Variable-weight products 3 Drugs 5 or 9 Coupons • Last digit: check digit UPC (barcode): basic features • Two sides separated watersheds/long guard bars • Total width of strips representing a number is 7 • Total width of black strips is odd (left side) – Example: 8 (WBBWBBB) UPC (barcode): basic features • Bars on two sides are like inverses. Bars on the right becomes spaces on the left and vice versa. – Example: the left representation of 8 is (WBBWBBB) and the right representation of 8 is (BWWBWWW) Odd width for left and even for right: enables scanners to detect orientation (up-side-down?) UPC (barcode) check scheme • Weighted modulo 10 check: check digit appended to make check sum divisible by 10 • How to calculate the check sum? How are the digits weighted? Validity of 9-87654-32109-8 • Rule: every valid UPC number has a special property • Step 1 (of checking validity): 9 8 7 6 5 4 3 2 1 0 9 8 x 3 1 3 1 3 1 3 1 3 1 3 1 = 27 8 21 6 15 4 9 2 3 0 27 8 • Step 2 (of checking validity): 27+8+21+6+15+4+9+2+3+0+27+8=130 • Step 3 (of checking validity): Is this “check sum” 130 divisible by 10? YES! The number is valid! Classwork: validity of UPC number Two-dimensional barcodes • Limited amount of data stored in 1D barcodes such as UPC • 2D barcode: rectangles (of different sizes) instead of strips (of different widths) • Primary example: QR (quick response) codes QR code: basic features • Storage capacity depends on data type, dimension and error-correction level – 40 different dimensions – 4 levels of error correction power Error-correction level % of info that can be restored Level L (Low) ~7% Level M (Medium) ~15% Level Q (Quartile) ~25% Level H (High) ~30% http://en.wikipedia.org/wiki/QR_code Play it! QR Code: Online Generator http://www.yj580.com/qr/ Numbers in Our Pockets -End-