Binary IO Writing and Reading Raw Data. Files Two major flavors of file: Text Binary.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
INSTRUCTION SET ARCHITECTURES
Data Manipulation Overview and Applications. Agenda Overview of LabVIEW data types Manipulating LabVIEW data types –Changing data types –Byte level manipulation.
Memory and Files Dr. Andrew Wallace PhD BEng(hons) EurIng
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Portability CPSC 315 – Programming Studio Spring 2008 Material from The Practice of Programming, by Pike and Kernighan.
A.How to create string controls and indicators B.Some string functions C.How to perform file input and output operations D.How to format text files for.
Implementation of a Stored Program Computer
CEG 320/520: Computer Organization and Assembly Language Programming1 CEG 320/520 Computer Organization and Assembly Language Programming.
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 13 Strings and File I/O  Read Bishop, Chapter 9.  Lab #13 and Homework #13 due next week.
CENG 311 Machine Representation/Numbers
Data Representation Prepared by Dr P Marais (Modified by D Burford)
February 14, 2005 Characters, Strings and the String Class.
CP104 Introduction to Programming File I/O Lecture 33 __ 1 File Input/Output Text file and binary files File Input/output File input / output functions.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Implementation of a Stored Program Computer ITCS 3181 Logic and Computer Systems 2014 B. Wilkinson Slides2.ppt Modification date: Oct 16,
Variables and Objects, pointers and addresses: Chapter 3, Slide 1 variables and data objects are data containers with names the value of the variable is.
IT253: Computer Organization Lecture 3: Memory and Bit Operations Tonga Institute of Higher Education.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Chapter 18 – Miscellaneous Topics. Multiple File Programs u Makes possible to accommodate many programmers working on same project u More efficient to.
CISC105 – General Computer Science Class 9 – 07/03/2006.
C++ for Engineers and Scientists Second Edition Chapter 8 I/O File Streams and Data Files.
Working With Main Memory. Why Main Memory Register space limited Used for communication.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
Byte Order Mohammad Kamal. Byte order Problem with byte order Numbers vs Data Practical example for reading data Exchanging Data between different systems.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 13 File Input and.
Big Endian vs. Little Endian Storage of Numeric Data Noah Mendelsohn Tufts University Web:
Springfield Technical Community College Center for Business and Technology.
Info stored in computer (memory) Numbers All in binaray – can be converted to octal, hex Characters ASCII – 1-byte/char Unicode – 2-byte/char Unicode-table.com/en.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Chapter 10 Instruction Sets: Characteristics and Functions Felipe Navarro Luis Gomez Collin Brown.
Lecture 5 A Closer Look at Instruction Set Architectures Lecture Duration: 2 Hours.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
1 CSC103: Introduction to Computer and Programming Lecture No 28.
Announcements There is a Quiz today. There were problems with grading assignment 2, but they should be worked out today The web page for correcting the.
Binary Files. Text Files vs. Binary Files Text files: A way to store data in a secondary storage device using Text representation (e.g., ASCII characters)
Base 16 (hexadecimal) Uses the decimal digits and the first letters of the alphabet to encode 4 binary bits (16=2 4 ) abcdef or ABCDEF.
Number Systems and Representations Binary Representation Binary Representation Signed numbers Signed numbers Very small and very big numbers Very small.
BINARY I/O IN JAVA CSC 202 November What should be familiar concepts after this set of topics: All files are binary files. The nature of text files.
Bitwise Operations C includes operators that permit working with the bit-level representation of a value. You can: - shift the bits of a value to the left.
Chapter 3 Data Representation
EET 2259 Unit 13 Strings and File I/O
Big-Endians Little-Endians and Bi-Endians
Chapter 6: Data Types Lectures # 10.
Memory, Data, & Addressing II CSE 351 Autumn 2017
Writing and Reading Raw Data
CPSC 315 – Programming Studio Spring 2012
A Closer Look at Instruction Set Architectures
CHAPTER 5 JAVA FILE INPUT/OUTPUT
Binary Code  
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Introduction to Programming
Computer Organization and ASSEMBLY LANGUAGE
ARM Arrays.
CSCI206 - Computer Organization & Programming
Portability CPSC 315 – Programming Studio
Little Endian vs. Big Endian (Intel vs. Motorola)
Bits and Bytes Topics Representing information as bits
ECEG-3202 Computer Architecture and Organization
Bits and Bytes Topics Representing information as bits
Chapter 9 Instruction Sets: Characteristics and Functions
A Closer Look at Instruction Set Architectures Chapter 5
ECEG-3202 Computer Architecture and Organization
EET 2259 Unit 13 Strings and File I/O
Block I/O fread and fwrite functions are the most efficient way to read or write large amounts of data. fread() – reads a specified number of bytes from.
Exploitation Part 1.
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Binary IO Writing and Reading Raw Data

Files Two major flavors of file: Text Binary

Text Files Text files – Easier to read by hand – Easier to reverse engineer – Easier to hand edit – More portable

Binary Files Binary files – More compact " " = 7 ascii chars = 7 bytes (or more) 1 int = 4 bytes – Faster No conversions from strings to numbers Easier random access – Known size for numerics

Working in Binary Mode Can specify binary more when opening a file

Working in Binary Mode Binary IO : n bytes starting at address s – Address expressed as char * char = 1 byte

Writing Write c-string:

Results Outputting ascii chars… Hex editor: Good text editor:Notepad:

Writing Non-Chars Write other types: – Get pointer to data – Cast as a char* – Use sizeof( ) to calculate number of bytes

Cast Types Static_cast sanity checks types Reinterpret_cast sanity checks size C-Style cast picks whichever

Cast Types Static_cast sanity checks types Reinterpret_cast sanity checks size C-Style cast picks whichever

Results Outputting ascii followed by bits for 15 (F) Hex editor: Good text editor:Notepad:

Size Int = 4 bytes

Results Outputting 15 (F 16 ) followed by 258 ( )

Endianess Endianess : bytes order of a word in main memory

Little vs Big Endian Big is "Normal": Little weird – Words in order – Bytes in a word backwards

Results Outputting 15 (F 16 ) followed by 258 ( ) Little Endian ArrangementMeaning 0F00 0F Little Endian ArrangementMeaning

Reading Need to read string, 2 ints – String unknown length

Reading Read string char by char:

Reading Same, using c-string

Reading Reading two ints:

Complex Files Graphic/Sound/etc… files have defined structure:

Other Option Structured text : XML – Less efficient than text – Machine parseable – Wide collection of tools