LING 408/508: Programming for Linguists Lecture 2 August 28 th.

Slides:



Advertisements
Similar presentations
ICS312 Set 2 Representation of Numbers and Characters.
Advertisements

The Binary Numbering Systems
Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
Digital Fundamentals Floyd Chapter 2 Tenth Edition
1 Information Representation (level ISA-3) Signed numbers and bit-level operations.
Data Representation Computer Organization &
Data Representation COE 205
CS 151 Digital Systems Design Lecture 4 Number Codes and Registers.
Chapter 3 Data Representation.
Chapter 3 Data Representation. Chapter goals Describe numbering systems and their use in data representation Compare and contrast various data representation.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Microprocessor Systems Design I
Digital Fundamentals Floyd Chapter 2 Tenth Edition
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
1.6 Signed Binary Numbers.
Dr. Bernard Chen Ph.D. University of Central Arkansas
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
Programmable Logic Controllers
Computers Organization & Assembly Language
Lecture 11: Machine Processing Intro to IT COSC1078 Introduction to Information Technology Lecture 11 Machine Processing James Harland
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
2-1 Chapter 2 - Data Representation Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Chapter Contents.
IT253: Computer Organization
Computer Architecture
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Data Representation.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
Why does it matter how data is stored on a computer? Example: Perform each of the following calculations in your head. a = 4/3 b = a – 1 c = 3*b e = 1.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
ICS312 Set 1 Representation of Numbers and Characters.
1 INFORMATION IN DIGITAL DEVICES. 2 Digital Devices Most computers today are composed of digital devices. –Process electrical signals. –Can only have.
Data Representation Dr. Ahmed El-Bialy Dr. Sahar Fawzy.
LING 408/508: Programming for Linguists Lecture 2 August 26 th.
Data Representation Bits, Bytes, Binary, Hexadecimal.
Number Systems Denary Base 10 Binary Base 2 Hexadecimal Base 16
1 Information Representation in Computer Lecture Nine.
Monday, January 14 Homework #1 is posted on the website Homework #1 is posted on the website Due before class, Jan. 16 Due before class, Jan. 16.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
CS 2130 Lecture 23 Data Types.
Data Encoding COSC Computers and Data Computers store information as sequences of bits Computers store many types of data: numbers text audio images.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
1 COMS 161 Introduction to Computing Title: Computing Basics Date: September 8, 2004 Lecture Number: 7.
Chapter 1 Representing Data in a Computer. 1.1 Binary and Hexadecimal Numbers.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Data Encoding COSC 1301.
Chapter 1 Digital Systems and Binary Numbers
Bits, Data Types, and Operations
Lec 3: Data Representation
Data Representation.
Lecture No. 4 Number Systems
Microprocessor Systems Design I
Microprocessor Systems Design I
CS1010 Programming Methodology
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
LING 388: Computers and Language
LING 408/508: Programming for Linguists
LING 408/508: Computational Techniques for Linguists
Digital Logic & Design Lecture 03.
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
Homework Homework Continue Reading K&R Chapter 2 Questions?
LING 388: Computers and Language
Comp Org & Assembly Lang
LING 388: Computers and Language
COMS 161 Introduction to Computing
LING 388: Computers and Language
Presentation transcript:

LING 408/508: Programming for Linguists Lecture 2 August 28 th

Today’s Topics continuing on from last time … quickie Homework 1

Introduction Storage: – based on digital logic – binary (base 2) – everything is a power of 2 – Byte: 8 bits = = = 91 (in decimal) – Hexadecimal (base 16) 0-9,A,B,C,D,E,F (need 4 bits) 5B (= 1 byte) = 5* = = B B

Introduction: data types Integers – In one byte (= 8 bits), what’s the largest and smallest number, we can represent? – Answer: – Why? – 1 – = 0 – = 127 – = -128 – = – 1 = – 1 =

Introduction: data types Integers – In one byte (= 8 bits), what’s the largest and smallest number, we can represent? – = 0 – = 127 – = -128 – = -1 0… ’s complement representation

Introduction: data types Integers – In one byte, what’s the largest and smallest number, we can represent? – Answer: using the 2’s complement representation – Why? super-convenient for arithmetic operations – “to convert a positive integer X to its negative counterpart, flip all the bits, and add 1” – Example: – = = 10 (decimal) – = = -10 (decimal) – flip + 1 = = Addition: = = 0 (ignore overflow)

Introduction: data types Typically 32 bits (4 bytes) are used to store an integer – range: -2,147,483,648 ( ) to 2,147,483,647 ( ) what if you want to store even larger numbers? – Binary Coded Decimal (BCD) – code each decimal digit separately, use a string (sequence) of decimal digits … …… byte 3byte 2byte 1byte 0 C: int

Introduction: data types what if you want to store even larger numbers? – Binary Coded Decimal (BCD) – 1 byte can code two digits (0-9 requires 4 bits) – 1 nibble (4 bits) codes the sign (+/-), e.g. hex C/D bytes (= 4 nibbles) bytes (= 5 nibbles) C D credit (+) debit (-)

Introduction: data types Typically, 64 bits (8 bytes) are used to represent floating point numbers (double precision) – c = x 10 8 (m/s) – coefficient: 52 bits (implied 1, therefore treat as 53) – exponent: 11 bits (not 2’s complement, unsigned with bias) – sign: 1 bit (+/-) C: float double wikipedia x86 CPUs have a built-in floating point coprocessor (x87) 80 bit long registers

Introduction: data types How about letters, punctuation, etc.? ASCII – American Standard Code for Information Interchange – Based on English alphabet (upper and lower case) + space + digits + punctuation + control (Teletype Model 33) – Question: how many bits do we need? – 7 bits + 1 bit parity – Remember everything is in binary … C: char Teletype Model 33 ASR Teleprinter (Wikipedia)

Introduction: data types order is important in sorting! 0-9: there’s a connection with BCD. Notice: code 30 (hex) through 39 (hex)

Introduction: data types Parity bit: – transmission can be noisy – parity bit can be added to ASCII code – can spot single bit transmission errors – even/odd parity: receiver understands each byte should be even/odd – Example: 0 (zero) is ASCII 30 (hex) = even parity: , odd parity: – Checking parity: Exclusive or (XOR): basic machine instruction – A xor B true if either A or B true but not both – Example: (even parity 0) xor bit by bit 0 xor 1 = 1 xor 1 = 0 xor 0 = 0 xor 0 = 0 xor 0 = 0 xor 0 = 0 xor 0 = 0 x86 assemby language: 1.PF: even parity flag set by arithmetic ops. 2.TEST: AND (don’t store result), sets PF 3.JP: jump if PF set Example: MOV al, TEST al, al JP

Introduction: data types UTF-8 – standard in the post-ASCII world – backwards compatible with ASCII – (previously, different languages had multi-byte character sets that clashed) – Universal Character Set (UCS) Transformation Format 8-bits (Wikipedia)

Introduction: data types Example: – あ Hiragana letter A: UTF-8: E38182 – Byte 1: E = 1110, 3 = 0011 – Byte 2: 8 = 1000, 1 = 0001 – Byte 3: 8 = 1000, 2 = 0010 – い Hiragana letter I: UTF-8: E38184 Shift-JIS (Hex): あ : 82A0 い : 82A2

Introduction: data types How can you tell what encoding your file is using? Detecting UTF-8 – Microsoft: 1 st three bytes in the file is EF BB BF (not all software understands this; not everybody uses it) – HTML: (not always present) – Analyze the file: Find non-valid UTF-8 sequences: if found, not UTF-8… Interesting paper: – archive.mozilla.org/projects/intl/UniversalCharsetDetection.html

Introduction: data types Filesystem: – different on different computers: sometimes a problem if you mount filesystems across different systems Examples: – FAT32 (File Allocation Table)DOS, Windows, memory cards – NTFS (New Technology File System) Windows – ext4 (Fourth Extended Filesystem)Linux – HFS+ (Hierarchical File System Plus)Macs limited to 4GB max file size

Introduction: data types Filesystem: – different on different computers: sometimes a problem if you mount filesystems across different systems Files: – Name (Path from / root) – Type (e.g..docx,.pptx,.pdf,.html,.txt) – Owner(usually the Creator) – Permissions (for the Owner, Group, or Everyone) – need to be opened (to read from or write to) – Mode: read/write/append – Binary/Text in all programming languages: open command

Introduction: data types Text files: – text files have lines: how do we mark the end of a line? – End of line (EOL) control character(s): LF 0x0A (Mac/Linux), CR 0x0D (Old Macs), CR+LF 0x0D0A (Windows) – End of file (EOF) control character: (EOT) 0x04 (aka Control-D) binaryvision.nl programming languages: NUL used to mark the end of a string

Quickie Homework 1 Recall the speed of light: c = x 10 8 (m/s) 1.Can a 4 byte integer be used to represent c exactly? Explain. 2.How much memory would you need to encode c using BCD notation? 3.Can the 64 bit floating point representation ( double ) encode c without loss of precision? Explain. 4.The 32 bit floating point representation ( float ) is composed of 1 bit sign, 8 bits exponent, and 23 bits coefficient (24 bits effective). Can it represent c without loss of precision?

Quickie Homework 1 Due Monday night – (by midnight in my box) Required format (for all homeworks unless otherwise specified): – Plain text or PDF formats only (no.doc,.docx etc.) – One file only (no multiple attachments) – Subject line: 408/508 Homework 1 – First line: your full name