LEC20081124 - Introduction to Computer Programming CSC180 Fall 2008 University of Toronto Multiple view of data#include int main cfw

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Computer Programming November 24, 2008 CSC180 Fall 2008, University of Toronto
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Multiple view of data #include <stdio.h> int main() { typedef unsigned short WORD; typedef unsigned char BYTE; union { struct { WORD ax, bx, cx, dx; } word; struct { BYTE al, ah, bl, bh, cl, ch, dl, dh; } byte; } regs; regs.byte.al = 0x34; regs.byte.ah = 0x12; CSC180 Fall 2008, University of Toronto 1
Background image of page 2
printf("%x\n", regs.word.ax); regs.word.bx = 0xabcd; printf("%x %x\n", regs.byte.bl, regs.byte.bh); return 0; } CSC180 Fall 2008, University of Toronto 2
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Bit-fields A bit-field is a set of adjacent bits within a storage unit. A bit-filed is like a small integer. Example: struct file_date { unsigned int day : 5; unsigned int month : 4; unsigned int year : 7; }; Multiple view of data: CSC180 Fall 2008, University of Toronto 3
Background image of page 4
/* bitfield.c */ union U { float x; struct { unsigned int fraction : 23; unsigned int exponent : 8; unsigned int sign : 1; } y; }; int main() { union U data; /* hex: 40880000 */ data.x = 4.25; printf("%x %x %x\n", data.y.sign, data.y.exponent, data.y.fraction); /* hex: beba1170 */ data.y.sign = 0x1; data.y.exponent = 0x7d; data.y.fraction = 0x3a1170; CSC180 Fall 2008, University of Toronto 4
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
printf("%g\n", data.x); return 0; } Example:
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/10/2011 for the course CSC 180 taught by Professor Na during the Fall '01 term at University of Toronto- Toronto.

Page1 / 18

LEC20081124 - Introduction to Computer Programming CSC180 Fall 2008 University of Toronto Multiple view of data#include int main cfw

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online