This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

Similar documents
Data Representation and Binary Arithmetic. Lecture 2

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

Number System (Different Ways To Say How Many) Fall 2016

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Chapter 2 Bits, Data Types, and Operations

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

Fundamentals of Programming (C)

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

Chapter 2 Bits, Data Types, and Operations

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Number Representations

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Chapter 2 Bits, Data Types, and Operations

3.1. Unit 3. Binary Representation

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

EE 109 Unit 2. Binary Representation Systems

Chapter 3. Information Representation

Do not start the test until instructed to do so!

The Binary Number System

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

Chapter 2 Bits, Data Types, and Operations

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

Under the Hood: Data Representation. Computer Science 104 Lecture 2

Max and Programming Is Max a Programming Language?

Do not start the test until instructed to do so!

Characters Lesson Outline

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

In further discussion, the books make other kinds of distinction between high level languages:

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

ASSIGNMENT 5 TIPS AND TRICKS

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

FA269 - DIGITAL MEDIA AND CULTURE

Midterm CSE 131 Winter 2012

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

Fundamentals of Programming

Lecture (09) x86 programming 8

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

CSE 30 Spring 2006 Final Exam

Chapter 2 Bits, Data Types, and Operations

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Chapter 8. Characters and Strings

Connecting UniOP to Datalogic Barcode Readers

Chapter 2 Number System

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

Oberon Data Types. Matteo Corti. December 5, 2001

User s Manual. Addendum to. Ranger Wedge Interface. Part No. 25-WEDGE-06A Ver. April 1999

Appendix A Developing a C Program on the UNIX system

Number Systems Base r

Midterm CSE 131 Winter 2014

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

CSE 30 Fall 2013 Final Exam

CSC 8400: Computer Systems. Represen3ng and Manipula3ng Informa3on. Background: Number Systems

CSE 30 Fall 2006 Final Exam

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

Introduction. Chapter 1. Hardware. Introduction. Creators of Software. Hardware. Introduction to Computers and Programming (Fall 2015, CSUS)

CSE 30 Fall 2012 Final Exam

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

Source coding and compression

CSE 30 Fall 2007 Final Exam

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

Chapter 1. Hardware. Introduction to Computers and Programming. Chapter 1.2

Simple Data Types in C. Alan L. Cox

Midterm CSE 131 Fall 2014

Variables and data types

PD1100 STAND-ALONE PROGRAMMING & USER S GUIDE. use the freedom

CSE 30 Spring 2007 Final Exam

CSE 30 Winter 2009 Final Exam

The following are the data types used in the C programming language:

ENCM 339 Fall 2017 Lecture Section 01 Lab 3 for the Week of October 2

Midterm CSE 131 Winter 2013

Characters & Strings in C

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }

Digital Representation

Do not start the test until instructed to do so!

4/14/2015. Architecture of the World Wide Web. During this session we will discuss: Structure of the World Wide Web

RS-232 Control of the Advantage EQ281/8, EQ282/8 and Advantage SMS200

CPSC 301: Computing in the Life Sciences Lecture Notes 16: Data Representation

CSE 30 Winter 2014 Final Exam

FD-011WU. 2D Barcode Reader User Guide V1.6CC

APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5

^BC Code 128 Bar Code (Subsets A, B, and C)

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

SECURITY PROTECTION OF SOFTWARE PROGRAMS BY INFORMATION SHARING AND AUTHENTICATION TECHNIQUES USING INVISIBLE ASCII CONTROL CODES*

Serial I/O. 4: Serial I/O. CET360 Microprocessor Engineering. J. Sumey

Final CSE 131 Fall 2014

Midterm Exam, Fall 2015 Date: October 29th, 2015

+ Inheritance. n Superclass (base class) higher in the hierarchy. n Subclass (child class) lower in the hierarchy

Transcription:

Dealing With ASCII ASCII, of course, is the numeric representation of letters used in most computers. In ASCII, there is a number for each character in a message. Max does not use ACSII very much. In the Max system, one number (called a symbol pointer) is used to represent each word. The program does not know all possible words, it simply assigns a symbol pointer to each word as it is entered. (First it checks to see if the word has already been entered, if it has, the existing symbol pointer is used.) These symbol pointers can be passed around very efficiently; only display objects need to look up the complete ASCII message. The type of message called a symbol is really nothing more than one of these pointers. This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor. From time to time we need to convert symbols to ASCII or vice versa. Symbols to ASCII To get the ASCII out of a symbol, use the spell object. A single symbol is converted to a spurt of ints. If several symbols are input as a list, the ASCII space (32) is inserted between each symbol. If you need to convert a series of individual symbols, you probably need to provide the space yourself. This shows how it works:

If you study the numbers in the bottom box, you can figure out the ASCII for "ASCII" is 65 83 67 73 73. If an int is applied to spell, the output is the ASCII representation of the digits of the int. It is important to keep this distinction clear. The number 114 ASCIIizes to 49 49 52. (Here's a quick way to convert a digit to ASCII: add 48.) This patcher illustrates the difference: ASCII to Symbols The sprintf object can be used to convert ASCII into symbols. Sprintf is a " string print formatter", in which parts of a message can be replaced by input data. The arguments to sprintf are the words of the message and placeholders %ld %f %s or %c. This example shows what happens.

The help file and manual are not complete of their description of sprintf, referring you to "any standard C language reference", not a common item on most coffee tables. Here's what the placeholders mean: %ld or % d Replace with an int and display as decimal. (Floats are truncated.) %x or % X Replace with an int and display as hexadecimal. %o Replace with an int and display as octal. (There's one you don't see much any more!) %u Replace with an int and display unsigned. (In theory, this should let you display numbers larger than 2874836647, but it doesn't.) %f Replace with a float. The format %.2f will round the float to 2 decimal places. %s Replace with a symbol. The format %.2s will show the first 2 letters of the symbol. %c Replace with character. There are other options in the C language printf, but they are not really appropriate to Max and not implemented. (Or partially implemented- try %05.5X) (A warning - C allows %* in some cases- that one will bomb.) We are interested in the %c placeholder, which converts an ASCII value into the appropriate character. To convert whole words, use this: Of course, you are limited in the number of %c's you can put in there. (more than 32 will crash some versions of Max.) If the ASCII codes include spaces (32), the output will be a list of distinct symbols. If a group of characters is all digits, a number will be generated instead of a symbol. Sprintf works like pack, in that each inlet remembers the last input, so you have to clear it with a list of 0s (non printing characters) between words.

Here is a patcher that illustrates the use of spell and sprintf: I opened the first message box and typed "which one". Spell converted this into ASCII which thresh made into a list, displayed in the lower left message. Sprintf converted the ASCII list back into a list of symbols. When you do this sort of thing, you'll have to warn the user about reserved words. Try this example with the phrase "bang the drum slowly".

You can also convert ASCII into symbols with the itoa object. This is an "unsupported external" by Steve Ellison. If you apply a list of ints to the left inlet, a symbol is output. At the right inlet, itoa works somewhat like accum. ASCII characters are gathered until there is a bang at the left. Note that if your symbol contains space characters, message boxes will display it enclosed in single quotes. If you should happen to convert that symbol back to ASCII with spell, the single quotes will not be included. There is little reason to create new symbols at run time. If you do much of this, the symbol table will eventually grow to unmanageable size, with a noticeable slowdown of all symbol operations. If ASCII is coming in, you should deal with it directly. Here are a few techniques:

Display ASCII Text To display ASCII, use the lcd object. The lcd is basically a quickdraw graphport; it has a lot of functions, including drawing with the mouse. The ASCII message will put a letter on the screen. To manage text, you need to position the cursor before writing and figure out how to wrap to the next line. This patcher demonstrates a couple of mechanisms: This is very limited. It will do for showing text from a serial port, but I wouldn't want to use it for any data entry. (I need my delete key!) The ASCII 13 that triggers a move to the next line is a carriage return, as supplied by the Mac return key. This is used by apple to indicate the end of a line. If you are getting serial data from a UNIX type system, end of line will be indicated by ASCII 10, the linefeed or "newline" character. Serial data sent from PCs use both. Enter, Edit And Save Text The text object provides entry of complex text. The help file illustrates its capabilities pretty well. Basically, the user can open a window and type in anything he pleases. The contents are converted to symbols when the window is closed, and can be dumped a line at a time. The whole works can be saved as a text file, other files can be read in, and so forth.

Detect And Respond To Typed Commands All you have to do is figure out the ASCII string you are looking for and watch for it with match. In this case, 102 105 114 101 spells fire. Notice the number box hanging on the key object. That's how I figure out ASCII values. (It's faster than any chart.) This is case sensitive, which can be a pain. To make caps irrelevant, do this: The expr $i1 32 takes advantage of the fact that the lower case ASCII characters are the same as the upper case with the 6th bit set. This will change some of the punctuation too, so if you are expecting any, use a split object to separate it out. (To find out more about OR ( ), read the essay on Max & numbers.)

You may find it interesting to use a binary number box to watch the shift and control keys modify the ASCII numbers. The option keys also change the ASCII code from a key, but not in any orderly fashion. We are getting ASCII out of the left outlet of the key object. Not all of the Mac keys can be read with ASCII, however. (The extra keys return ASCII, but many of them have the same values.) If you want to trigger events off the function keys or the arrow keys, you need to use the right outlet of key, which displays Apple's key codes. Every key on the keyboard has a unique code: F1 is 122, F2 is 120. They don't make any sense, but each key code is unique. Incidentally, you can't detect the help key by any method, because Max has its own idea of what to do when you press the help key. To define other command-key combinations, use the menubar object. Using Lin to get ASCII I've written an Lobject to simplify the input of ASCII from the keyboard. The helpfile pretty much explains it: The right outlet of Lin will give the message in progress (including deleting the last character if the message "back" is received.) the message will be sent out of the left outlet when a return is input. You can easily detect expected messages with the Like object.

ASCII Codes Here's a table of the ASCII codes. The enigmatic ones like ETB apply to teletypes and the like. You might get them from some serial applications. The parentheses indicate the Mac key that generates them. 0 NUL 34 " 1 SOH (Home) 35 # 2 STX 36 $ 3 ETX (enter) 37 % 4 EOT (end ) 38 & 5 ENQ 39 ' 6 ACK 40 ( 7 BEL 41 ) 8 BS (delete on Mac) 42 * 9 HT (Tab) 43 + 10 Line feed 44, 11 VT (Page Up) 45-12 Form Feed (Page Down) 46. 13 CR (return) 47 / 14 S0 48-57 numbers 0-9 15 SI 58 : 16 DLE (all F keys) 59 ; 17 DC1 60 < 18 DC2 61 = 19 DC3 62 > 20 DC4 63? 21 NAK 64 @ 22 SYN 65-90 Capitol A -Z 23 ETB 91 [ 24 CAN 92 \ 25 EM 93 ] 26 SUB 94 ^ 27 escape (also clear) 95 _ 28 cursor right 96 ` 29 cursor left 97-122 letters a - z 30 cursor up 123 { 31 cursor down 124 32 space 125 } 33! 126 ~ 127 DEL