Enumerations.

Slides:



Advertisements
Similar presentations
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
Advertisements

Enumeration Data Type enum Day {SUN, MON, TUE, WED, THU, FRI, SAT}; Day today; today = WED; if (today == FRI) cout
 2000 Prentice Hall, Inc. All rights reserved. Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
1 Bitwise Operators. 2 Bits and Constants 3 Bitwise Operators Bitwise "and" operator & Bitwise "or" operator | Bitwise "exclusive or" operator ^ Bitwise.
1 Bitwise Operators. 2 Bitwise Operators (integers) Bitwise "and" operator & Bitwise "or" operator | Bitwise "exclusive or" operator ^ Bitwise "ones complement"
21 August (B.V.Patel institute of BMC & IT) STRUCTURE AND UNIONS.
12 주 강의 The preprocessor. The use of #include #include #include “ filename ” ::: current directory  system-dependent places #include ::: system dependent.
Bitwise Operators Fall 2008 Dr. David A. Gaitros
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.
Ch Chapter 4 Basic Data Types and Variables 4.1 Basic Data Types In C TABLE 4.1 Introduction to Basic Data Types in C Type SizeDescription char 1.
Chapter 10 Structures, Unions, Bit Manipulations, and Enumerations Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering.
CPT: Types/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to look at how new types can be created 6. User-defined.
Weekly C-minar Week 0. Today: Steps of the compile Basic inclusion/syntax rules Low-cost containment Debugging.
Introduction to Computer Organization & Systems Topics: Command Line Bitwise operators COMP Spring 2014 C Part V.
Enumerated Types Mr. Dave Clausen La Cañada High School.
1 dimensional static Array Int[] a = new int[4]; A[0]A[1]A[2]A[3] Int[] b= new int[1]; B[0] Array is a list of variables having same name and same data.
Quick Summary C++/CLI Basics Data Types Controls Arrays In-class assignments.
Chapter 8 Bit Operations By C. Shing ITEC Dept Radford University.
What do I need to Know For My Assignment?. C Pointer Review To declare a pointer, we use the * operator. This is similar to but different from using *
10 주 강의 Bitwise operators and Enumeration types. 컴퓨터환경 8-bit bytes, 4-bytes words Two ’ s complement ASCII character codes.
Enumeration Types Managing Ordered Sets. Enumeration types are designed to increase the readability of programs Used to define a set of named constants.
5 Day Forecast Mon Tues Wed Thu Fri.
LESSON 06.
The Machine Model Memory
Chapter 6 – Data Types CSCE 343.
Data types Data types Basic types
Structure, Unions, typedef and enumeration
Lecture 16: Introduction to Data Types
Enumeration Types and typedef
GANTT CHARTS Example Example Example Example text Tasks Example 1
Instructor: Ioannis A. Vetsikas
typedef typedef int Index; typedef char Letter; Index i; i = 17;
Mon – 2Tue – 3Wed – 4Thu - 5Fri - 6Sat - 7Sun - 8 Mon – 9Tue – 10Wed – 11Thu - 12Fri – 13Sat – 14Sun -15 Mon – 16Tue – 17Wed – 18Thu - 19Fri – 20Sat –
C: Primer and Advanced Topics
C Structures, Unions, Bit Manipulations and Enumerations
Structures and Union.
Enumerations.
MON TUE WED THU
Bits and Bytes Topics Representing information as bits
Bits and Bytes Topics Representing information as bits
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
Bits and Bytes Topics Representing information as bits
ANNUAL CALENDAR HOLIDAYS JANUARY FEBRUARY MARCH APRIL MAY JUNE
HOLIDAYS ANNUAL CALENDAR JANUARY FEBRUARY MARCH APRIL MAY JUNE
January Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
Chapter 1: Introduction to Data Structures(8M)
HOLIDAYS ANNUAL CALENDAR JANUARY FEBRUARY MARCH APRIL MAY JUNE
2008 Calendar.
Structures and Union.
January MON TUE WED THU FRI SAT SUN
Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
Sun Mon Tue Wed Thu Fri Sat
Structures and Union.
1/○~1/○ weekly schedule MON TUE WED THU FRI SAT SUN MEMO
Bitwise Operators.
January MON TUE WED THU FRI SAT SUN
S M T W F S M T W F
2016 | 10 OCT SUN MON TUE WED THU FRI SAT
C Language B. DHIVYA 17PCA140 II MCA.
Sun Mon Tue Wed Thu Fri Sat
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
1 January 2018 Sun Mon Tue Wed Thu Fri Sat
2008 Calendar.
Presentation transcript:

Enumerations

Review two dimensional array char *p[2] = {“MB”, “Mercedes Bentz”};

Review – function pointer

Bit Operations most CPU processes data in word unit 32 bits are processed in parallel if you need just one bit of information, the remaining space for 31bits is wasted

C Bitwise Operators

Bitwise Complement int a = 70707; a ~a 00000000 00000001 00010100 00110011 ~a 11111111 11111110 11101011 11001100 -70708

2’s Complement int a = 70707; a ~a 2’s 00000000 00000001 00010100 00110011 ~a 11111111 11111110 11101011 11001100 -70708 2’s 11111111 11111110 11101011 11001101 -70707

Bitwise Logical Operators

Shift Operators

Masks void bit_print(int a) { int i; int n = sizeof(int) * CHAR_BIT; /* in limits.h */ int mask = 1 << (n - 1); /* mask = 100...0 */ for (i = 1; i <= n; ++i) { putchar(((a & mask) == 0) ? '0' : '1'); a <<= 1; if (i % CHAR_BIT == 0 && i < n) putchar(' '); } bit_print(33333); 00000000 00000000 10000010 00110101

Packing /* Pack 4 characters into an int. */ #include <limits.h> int pack(char a, char b, char c, char d) { int p = a; /* p will be packed with a, b, c, d */ p = (p << CHAR_BIT) | b; p = (p << CHAR_BIT) | c; p = (p << CHAR_BIT) | d; return p; }

Unpacking /* Unpack a byte from an int. */ #include <limits.h> char unpack(int p, int k) /* k = 0, 1, 2, or 3 */ { int n = k * CHAR_BIT; /* n = 0, 8, 16, or 24 */ unsigned mask = 255; /* low-order byte */ mask <<= n; return ((p & mask) >> n); }

Enumeration Types enum day {sun, mon., tue, wed, thu, fri, sat); enum day d1, d2, holidays; enumerators are of int type the first one is zero, .. enum suit {club = 3, diamonds, hearts = 0; spades} a, b;

Enumeration Types type casting applies

Preprocessor works before compilation macros #include includes “file name” or search <file name> in other directories macros #define SEC_PER_DAY (60 * 60 * 24) #define SQ(x) ((x) * (x)) #define max(x, y) (((x) > (y)) ? (x) : (y))

Conditional Compilation set the value of win using #define

Other directives defined operator debugging code # if (defined(HP) || defined(SUN)) && !defined(SUN3) ...... #endif debugging code # if DEBUG #if HEAP_SIZE < 24000 # error “not enough space for malloc”

Stringization #define message(a, b) printf (#a “and “ #b); message(Hail, SKKU) is replaced by printf(“Hail” “and” “SKKU”) #define X(i) X ## i X(2) is replaced by X2