Byte Order Mohammad Kamal. Byte order Problem with byte order Numbers vs Data Practical example for reading data Exchanging Data between different systems.

Slides:



Advertisements
Similar presentations
Socket Programming 101 Vivek Ramachandran.
Advertisements

Programming with UDP – I Covered Subjects: IPv4 Socket Address Structure Byte Ordering Functions Address Access/Conversion Functions Functions: 1.socket()
1 Today’s lecture  Last lecture we started talking about control flow in MIPS (branches)  Finish up control-flow (branches) in MIPS —if/then —loops —case/switch.
IT253: Computer Organization Lecture 6: Assembly Language and MIPS: Programming Tonga Institute of Higher Education.
This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Malloc Recitation Section K (Kevin Su) November 5 th, 2012.
© 2010 Kettering University, All rights reserved..
CMPUT Computer Organization and Architecture I
Python Programming Chapter 1: The way of the program Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
#include DatatypeDescription int8_t uint8_t int16_t uint16_t int32_t uint32_t Signed 8-bit integer Unsigned 8-bit integer Signed 16-bit integer Unsigned.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
Portability CPSC 315 – Programming Studio Spring 2008 Material from The Practice of Programming, by Pike and Kernighan.
Adapted from Dr. Craig Chase, The University of Texas at Austin.
Implementation of a Stored Program Computer
August 26 TA: Angela Van Osdol Questions?. What is a computer? Tape drives? Big box with lots of lights? Display with huge letters? Little box with no.
Sockets COS 518: Advanced Computer Systems Michael Freedman Fall
CHAPTER 1: INTORDUCTION TO C LANGUAGE
Data Types in the Kernel Sarah Diesburg COP 5641.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
CSCI 136 Lab 1 Outline Go through the CD attached to the textbook. Homework Hints 135 Review.
Operating Systems Chapter 9 Distributed Communication.
ASN.1 CNS 4650 Fall 2004 Rev. 2.
CISCO NETWORKING ACADEMY Chabot College ELEC Addressing & Routing Foundation Concepts.
Instruction Set Architecture
Data Representation - Part I. Representing Numbers Choosing an appropriate representation is a critical decision a computer designer has to make The chosen.
UNIT - 1Topic - 3. Computer software is a program that tells a computer what to do. Computer software, or just software, is any set of machine-readable.
1 Project 3: An Introduction to File Systems CS3430 Operating Systems University of Northern Iowa.
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.
CSC 2400 Computer Systems I Lecture 5 Pointers and Arrays.
C programming or Fun with pointers Tutorial #2 CPSC 261.
Bits and Bytes Spring, 2015 Topics Why bits? Representing information as bits Binary / Hexadecimal Byte representations »Numbers »Characters and strings.
Week 2 - Wednesday.  What did we talk about last time?  C compilation model  Lab 1.
CSCI 136 Lab 1: 135 Review.
1 COMP/ELEC 429/556 Introduction to Computer Networks Creating a Network Application Some slides used with permissions from Edward W. Knightly, T. S. Eugene.
Big Endian vs. Little Endian Storage of Numeric Data Noah Mendelsohn Tufts University Web:
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.
Assembly language: arithmetic and load/store instructions Ellen Spertus MCS 111 September 17, 2002.
 Socket class ◦ provides a rich set of methods and properties for network communications. The Socket class allows you to perform both synchronous and.
The single most important skill for a computer programmer is problem solving Problem solving means the ability to formulate problems, think creatively.
Address alignment When a word (4-bytes) is loaded or stored the memory address must be a multiple of four. This is called an alignment restriction. Addresses.
Byte Addressability Bytes are always 8 bits Word length typically ranges from 16 to 64 bits. Memory location assignments refer to successive byte locations.
Memory, Bits, & Bytes. Memory Part of the computer where programs and data are stored. Read and written (changed). Bit – Binary digit – Basic unit of.
Binary IO Writing and Reading Raw Data. Files Two major flavors of file: Text Binary.
First Foray into Programming (the hard way). A reminder from last lesson: A machine code instruction has two parts:  Op-code  Operand An instruction.
Number Systems and Representations Binary Representation Binary Representation Signed numbers Signed numbers Very small and very big numbers Very small.
CMSC 202 Lesson 26 Miscellaneous Topics. Warmup Decide which of the following are legal statements: int a = 7; const int b = 6; int * const p1 = & a;
Sockets Intro to Network Programming. Before the internet... Early computers were entirely isolated No Internet No network No model No external communications.
Variables Bryce Boe 2012/09/05 CS32, Summer 2012 B.
Advanced Computer Systems
Big-Endians Little-Endians and Bi-Endians
CS/COE 0447 (term 2181) Jarrett Billingsley
CPSC 315 – Programming Studio Spring 2012
Vocabulary Prototype: A preliminary sketch of an idea or model for something new. It’s the original drawing from which something real might be built or.
Week 7 Part 2 Kyle Dewey.
EECE-276 Fall 2003 Microprocessors & Microcontrollers II
Portability CPSC 315 – Programming Studio
7. End-to-end data Rocky K. C. Chang Department of Computing
Little Endian vs. Big Endian (Intel vs. Motorola)
Bits and Bytes Topics Representing information as bits
August 29 New address for Fang-Yi
A Closer Look at Instruction Set Architectures Chapter 5
CS111 Computer Programming
The University of Adelaide, School of Computer Science
University of Gujrat Department of Computer Science
Comp Org & Assembly Lang
Comp Org & Assembly Lang
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
January 16 The books are here. Assignment 1 now due Thursday 18 Jan.
Presentation transcript:

Byte Order Mohammad Kamal

Byte order Problem with byte order Numbers vs Data Practical example for reading data Exchanging Data between different systems

Problem: Computers speak different languages, like people. Some write data "left-to-right" and others "right-to-left". A machine can read its own data just fine - problems happen when one computer stores data and a different type tries to read it. Solutions : Agree to a common format (i.e., all network traffic follows a single format), Always include a header that describes the format of the data. If the header appears backwards, it means data was stored in the other format and needs to be converted.

Numbers vs. Data A number is an abstract concept, such as a count of something. You have ten fingers. The idea of "ten" doesn't change, no matter what representation you use Data is a physical concept, a raw sequence of bits and bytes stored on a computer. Data has no inherent meaning and must be interpreted by whoever is reading it. Data is like human writing, which is simply marks on paper. There is no inherent meaning in these marks. If we see a line and a circle (like this: |O)

Byte Example W 0 12 X 1 34 Y 2 56 Z 3 78 void *p char *c Null void *p = 0; // p is a pointer to an unknown data type // p is a NULL pointer -- do not dereference char *c; // c is a pointer to a single byte c = (char *)p;

So, what's the problem? Problems happen when computers try to read multiple bytes. Big endian machine: Stores data big-end first. When looking at multiple bytes, the first byte (lowest address) is the biggest. Motorola processors (those used in Mac's) use "Big Endian" byte order Little endian machine: Stores data little-end first. When looking at multiple bytes, the first byte is smallest. Intel processors (those used in PC's) use "Little Endian" byte order

Another Example W 0 12 X 1 34 Y 2 56 Z 3 78 void *p int *s int *s; // pointer to a short int (2 bytes) s = 0; // point to location 0; *s is the value s = (int *)p;

The NUXI problem Issues with byte order are sometimes called the NUXI problem: UNIX stored on a big-endian machine can show up as NUXI on a little-endian one. By the way, the big-endian / little-endian naming comes from Gulliver's Travels, where the Lilliputans argue over whether to break eggs on the little-end or big-end. Sometimes computer debates are just as meaningful W 0 12 X 1 34 Y 2 56 Z 3 78 void *p int *s

Exchanging Data Between Endian Machines Solution 1: Use a common format. The easiest approach is to agree to a common format for sending data over the network. The standard network order is actually big-endian. To convert data to network order, machines call a function hton (host- to-network).

include a magic number, such as 0xFEFF, before every piece of data. If you read the magic number and it is 0xFEFF, it means the data is in the same format as your machine, and all is well. If you read the magic number and it is 0xFFFE (it is backwards), it means the data was written in a format different from your own. You'll have to translate it. Solution 2: Use a Byte Order Mark (BOM)

Why are there Endian issues at all? Can't we just get along? Each byte-order system has its advantages. Little-endian machines let you read the lowest- byte first, without reading the others. You can check whether a number is odd or even (last bit is 0) very easily, which is cool if you're into that kind of thing. Big-endian systems store data in memory the same way we humans think about data (left-to- right), which makes low-level debugging easier.

Thanks For listening