CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22

Similar documents
CENG 334 Computer Networks. Laboratory I Linux Tutorial

Programming Studio #1 ECE 190

Practical Session 0 Introduction to Linux

Programming Studio #1 ECE 190

Introduction to the Linux Command Line

commandname flags arguments

Unix Basics. Systems Programming Concepts

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Chapter-3. Introduction to Unix: Fundamental Commands

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

Working with Basic Linux. Daniel Balagué

Laboratory 1 Semester 1 11/12

CHAPTER 1 UNIX FOR NONPROGRAMMERS

MTU Computer Structure

CS Fundamentals of Programming II Fall Very Basic UNIX

UNIX File Hierarchy: Structure and Commands

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

UNIX Quick Reference

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

The Unix Shell & Shell Scripts

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

On successful completion of the course, the students will be able to attain CO: Experiment linked. 2 to 4. 5 to 8. 9 to 12.

Linux Command Line Primer. By: Scott Marshall

Computer Systems and Architecture

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

Oxford University Computing Services. Getting Started with Unix

Introduction to Unix: Fundamental Commands

CS CS Tutorial 2 2 Winter 2018

Outline. Structure of a UNIX command

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

Systems Programming and Computer Architecture ( ) Exercise Session 01 Data Lab

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

Unix Introduction to UNIX

UNIX Quick Reference

Introduction to the UNIX command line

Getting Started. Running Utilities. Shells. Special Characters. Special Characters. Chapter 2 Unix Utilities for non-programmers

Introduction: What is Unix?

Introduction to Supercomputing

IMPORTANT: Logging Off LOGGING IN

2) clear :- It clears the terminal screen. Syntax :- clear

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

National University of Computer and Emerging Sciences Operating System Lab - 02 Lab Manual

Unix Workshop Aug 2014

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

EKT332 COMPUTER NETWORK

Computer Systems and Architecture

CSE 390a Lecture 3. Multi-user systems; remote login; editors; users/groups; permissions

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

CSCI 2132 Software Development. Lecture 4: Files and Directories

Part I. Introduction to Linux

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Research. We make it happen. Unix Basics. User Support Group help-line: personal:

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

Introduction to Linux

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

Exercise 1: Basic Tools

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

LOG ON TO LINUX AND LOG OFF

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

CS : Computer Programming, Spring 2000 Programming Project #1: Thinking of a Number Due in class Thursday 27 January 2000

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

INTRODUCTION TO BIOINFORMATICS

Operating Systems, Unix Files and Commands SEEM

Welcome to Linux. Lecture 1.1

Lab 1 Introduction to UNIX and C

Introduction to Linux

CSC111 Computer Science II

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

INSE Lab 1 Introduction to UNIX Fall 2017

Introduction to Algorithms and Programming I Lab. Exercises #1 Solution

Introduction to Linux Workshop 1

Some useful UNIX Commands written down by Razor for newbies to get a start in UNIX

5/8/2012. Creating and Changing Directories Chapter 7

Presented by Bill Genske Gary Jackson

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

A Brief Introduction to Unix

SECTION -C. Getting Started with UNIX

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Introduction to Linux

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

Introduction to Linux

5/8/2012. Encryption-based Protection. Protection based on Access Permission (Contd) File Security, Setting and Using Permissions Chapter 9

CS4350 Unix Programming. Outline

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Introduction to Linux. Fundamentals of Computer Science

CS246 Spring14 Programming Paradigm Notes on Linux

Unix Tutorial Haverford Astronomy 2014/2015

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

Files and Directories

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

Introduction to Lab Practicals (Lab Intro 3) Access Control, Synchronisation and Remote Access

CSC209. Software Tools and Systems Programming.

Transcription:

CSCE 212H, Spring 2008, Matthews Lab Assignment 1: Representation of Integers Assigned: January 17 Due: January 22 Manton Matthews January 29, 2008 1 Overview The purpose of this assignment is to become more familiar with bit-level representations of integers and bitwise operators. We will begin by doing a few unix calastenics on the Linux workstations. Then you will be ask to answer a series of questions and solve a series of programming exercises. The portions of this assignment are: 1. Unix Calastenics ssh changing your password making a subdirectory changing permissions copying files submitting assignments 2. Unsigned integer representations 3. Two s complement representation 4. Bitwise operations in C 5. IEEE floating Point representation 6. Implementations Logistics All labs will be submitted electronically using dropbox. If there are any corrections or modifications to assignments these will be sent out via email and posted to the website. 1

1.1 CSE Secure Website The Department Website has information on the Departement academic programs, faculty etc. For this lab we are interested in the secure web site https://www.cse.sc.edu that contains information that we would like to make available to students but not to the rest of the world. To get access the this site you must supply your Unix login-name and password. Usually the name is the same as your name in the engr domain, but your password will be different. Go to this site (https://www.cse.sc.edu Note carefully the s in https!) and login. Passwords Your initial password is set to a function of your student ID. This is not secure at all and your should change your password when you first login. A good password: is long enough to make it difficult to guess by brute force, is not an english word (This would be succeptible to dictionary attacks.), and contains a mixture of uppercase, lowercase and special characters. For detailed instructions on changing your password see https://www.cse.sc.edu. 1.2 Important Links on CSE Secure Site There are a large number of important links on the secure site and I encourage you to explore for your self. However, there are a few that I would like to point to for help in our labs. Dropbox/Center - for assignments Password CSE Computing: Lab policy, Workstations, Host Usage GradeBook Center - our version of blackboard for assignemnts/grades Remote Access Networked Resources 2 Start Up Instructions Start by signing on to your engineering domain account. You then need to run the program SSH, Secure SHell, (Start Programs CSE_Apps?). This program allows for secure connections to remote computers. All transmissions including the initial username and password are encrypted for security. This particular 2

program is already available in the labs but it is also available for downloading and installing on your personal machines from The secure CSE site FTP (upper right menu) Windows. More details on SSH may be found using google. As part of making a connection your need to specify the remote computer. This can be done by giving an IP address or a domain qualified name. For our purposes we will be connecting to the Linux machines in 1D41 or 1D43. The machine names are are given below. You will also need to give your Unix login name. During our labs it will be a good idea for us to logon to different machines. To simplify this I have listed a collection of SUN workstation names. IP ADDRESS HOSTNAME MACHINE TYPE Lab 1D39 129.252.130.165 apollon.cse.sc.edu # Linux lab Precision 380 129.252.130.166 demeter.cse.sc.edu # Linux lab Precision 380 129.252.130.167 eos.cse.sc.edu # Linux lab Precision 380 129.252.130.168 moira.cse.sc.edu # Linux lab Precision 380 129.252.130.169 clotho.cse.sc.edu # Linux lab Precision 380 129.252.130.170 gorgon.cse.sc.edu # Linux lab Precision 380 129.252.130.171 pluto.cse.sc.edu # Linux lab Precision 380 129.252.130.172 helios.cse.sc.edu # Linux lab Precision 380 129.252.130.173 hera.cse.sc.edu # Linux lab Precision 380 129.252.130.174 herakles.cse.sc.edu # Linux lab Precision 380 129.252.130.175 kronos.cse.sc.edu # Linux lab Precision 380...... # Sun Machines are older Lab 1D45 129.252.130.147 cerberus.cse.sc.edu # Linux lab Optiplex 270 129.252.130.148 hermes.cse.sc.edu # Linux lab Optiplex 270 129.252.130.149 hebe.cse.sc.edu # Linux lab Optiplex 270 129.252.130.153 minerva.cse.sc.edu # Linux lab Precision 650 129.252.130.154 thetis.cse.sc.edu # Linux lab Precision 650 129.252.130.155 erida.cse.sc.edu # Linux lab Precision 650 129.252.130.156 embedded.cse.sc.edu # Linux lab Precision 650 129.252.130.157 tartarus.cse.sc.edu # Linux lab Precision 370 129.252.130.158 circe.cse.sc.edu # Linux lab Precision 370 129.252.130.159 metis.cse.sc.edu # Linux lab Precision 370 129.252.130.160 kalypso.cse.sc.edu # Linux lab Precision 370 129.252.130.161 hestia.cse.sc.edu # Linux lab Precision 370 129.252.130.162 chimera.cse.sc.edu # Linux lab Precision 380 129.252.130.163 hades.cse.sc.edu # Linux lab Precision 380 129.252.130.164 skylla.cse.sc.edu # Linux lab Precision 380 3

Your may save this session so that future connections to this machine are easy. 4

2.1 Basic Unix Commands Basic Commands Dealing with the Hierarchy ls list the contents of the current working directory cd dir change working directory to the directory dir,.. means parent pwd prints the current working directory mkdir file creates a new directory date prints the date Simple File Commands mv file1 file2 renames file1 with name file2 (old file2 destroyed) rm file removes file cp file1 file2 makes a copy of file1 and names it file2 cat file catenate file, writes file to the standard output (equivalent of MS-DOS type) vim file invokes the vim editor on file (vi) pico file invokes the pico editor on file gcc prog.c invokes the c compiler on the program prog.c creates a.out(cc) less file page through the file one screen at a time(more) sort file sorts the file grep pattern files print the lines that match the pattern from the files wc file wordcount counts the characters, words and lines in file find path options actions search subdirectory path for files e.g. find. -name *.c -print search current subtree print filenames ending in.c Printer Commands lpr file prints file lpr -Pln print file on the printer named ln a2ps file **converts an ascii text file to Postscript for printing on laser printers Assistance Commands man cmd prints on-line manual entry for the command cmd man -k subject gives list of manual entries related to the keyword subject Process Manipulating Commands ps print list of current processes kill -sig pid send the signal sig to the process with id pid history prints the hsitroy list of commands alias newname=oldcommand gives an oldcommand a new name (usually shorter) exit terminate shell Communication Commands mail [user] read mail [send mail to user] ssh machine create a secure connection to another machine sftp machine secure file transfer to/from another machine Environmental Commands passwd allows the user to change his password quota display disk usage and quotas du disk usage for a specific subtree df print the amount of free disk space env print the environment variables set print the values of the shell variables Who is Who Commands who 5 who is logged in currently w who is logged in and what are they doing finger name who is this person

3 Permissions Each file in the UNIX system has a set of permissions associated with it describing how and by whom it may be accessed. There are there types of access to files (1) read access, (2) write access and (3) execute access. For instance a user could have read permission, but not write or execute permission. To encode these 3 bits of information requires a 3-bit binary string or an octal digit. In this encoding the READ permission bit is the highest bit, the WRITE permission bit is the next highest, and the execute permission bit is the lowest. For instance read and execute but not write permission would be represented by 101 = 5 octal. For each file there are 3 sets of permissions each represented as an octal digit. These are the permissions for the owner, the permission for the other users in the owner s group, and the permission for all other users. To see the permission information associated with a file one can use the command ls -l as in the example below. The output of the ls - l translates the permissions into a symbolic representation of 10 characters. The leading character tells what kind of file this is. Here d means a directory and - means an ordinary file. There are other possible types and the reader can see the ls manual page for details. There is a leading character and then 3 groups of 3 characters. The first group is for the owner and the next for the owner s group and finally for all other users. Using regular expression notation each of the groups is (r -) (w -) (z -) which of course means the first character is r or -, the second w or - and finally the third x or -. If there is an r then there is read permission, and conversely if there is a dash where the r would be then there is not read permission. To set permissions explicitly one can use the chmod command. Chmod can use a 3-digit octal number. % cd sample % ls -l testfile -rw-rw-rw- 1 matthews 37 Dec 9 18:49 testfile % chmod 750 testfile % ls -l testfile -rwxr-x 1 matthews 37 Dec 9 18:49 testfile Setting up your 212 Directory To create a subdirectory for your CSCE 212 files use the command mkdir 212 and then use chmod 0700 212 to protect this subdirectory. Then use the command cd 212 to move into this subdirectory and mkdir Lab1 to create a subdirectory for the files of Laboratory 1. Finally move into the Lab1 directory with cd Lab1. Copying the set up Files There is a directory /class/csce212-501 that contains files for the various labs during the course. There are several subdirectories for files, most notably Examples and Lab1. To get started copy the file showbytes.c using the command cp /class/csce212-501/labs/lab01/show_bytes.c. 6

The. in the previous command refers to the current working directory. After copying the file you can use ls to show the files in the current directory and verify that the copy command worked. 4 Unsigned Integers The representation of unsigned integers is essentially binary with no sign bit. So if there are w bits then the range is from 0 to 2 w 1. The unsigned integers form a ring, actually the ring Z 2 w, i.e., the integers mod 2 w. Both multiplication and addition arfe associative and commutative. Also multiplication distributes over addition. However, normal ordering operations are not always satisfied. In the integers if x < y and k > 0 then kx < ky. There are cases when ky overflows for which this does not hold. Question 1 Give an example of unsigned integers x, y and k for which x < y, k > 0 and kx > ky. Question EC 1 Give an example of unsigned integers x, y and k for which x < y, k > 0 and kx = ky or show that no such unsigned integers exist. Limits.h The file /usr/include/limits.h contains constants that give limits on values. Question 2 What is the value of UINT MAX? Unsigned Int Program Develop a program u.c that uses the function show_bytes and an unsigned integer to convert your student ID to hex. Question 3 What is the value of your student ID in binary? Question 4 Is the value of your student ID such that you could have done the previous program with two s complement integers? 5 Two s Complement Representation of Integers Two s complement is the prime method for representing signed integers. For a w-bit representation if the highest order bit is zero then number is positive and the remaining bits are the binary representation of the integer. If the highest order bit is 1 then the number is negative and its value is 2 w 1 + the value of the unsigned int in the remaining 31 bits. Multiplying by 1 changes the sign, form two s complement integers you can take the two s complement by complementing each bit (1 s complement) and incrementing the result by 1. So 7

twos_comp(x) = ( x) + 1; Int C Puzzles For these puzzles assume a machine with 32 bit word size. Assuming the following initialization int x = foo(); int y = bar(); unsigned ux = x; unsigned uy = y; // x and y can be any 32 bit two s complement int s Question 5 Determine which of these conditions is true? For each of the following C expressions, either: Argue that is true for all argument values Give example where not true. Precondition Question P1 x < 0??? ((x 2) < 0) P2??? ux 0 P3 x&7 == 7??? (x << 30) < 0 P4??? ux > 1 P5 x > y??? x < y P6??? x x 0 P7 x > 0&&y > 0??? x + y > 0 P8 x 0??? x 0 P9 x 0??? x 0 6 IEEE Floating Point Representation The 32 bit IEEE floating point representation has three components: 1. the sign bit (1 bit) 2. the exponent (8 bits) 3. the mantissa (23 bits with implied leading 1 for 24 bits) For the answers to questions 6-9 in addition to your answer give the program that lead you to the answer. Question 6 Using showbytes and many examples of floats determine which bit is the sign bit? Question 7 Using showbytes and many examples of floats determine which bits are the exponent? 8

Question 8 Using showbytes and many examples of floats determine which bits are the mantissa? Question 9 Find the smallest float x such that x + 1 == x. 9