Survey Motivation 29.5 / 40 class is required Concerns 6 / 40 not good at examination That s why we have 3 examinations 6 / 40 this class sounds difficult 8 / 40 understand the instructor Want class to be 27 / 40 challenging 8 / 40 easy
overview bit, byte and int float point [C] basics, bitwise operator, control flow [C] scopes rules, pointers, arrays [C] structs, mallocs [C] large program (linked list) Machine Prog: ISA, Compile, movq Machine Prog: Control Code (condition, jump instruction) Machine Prog: Array allocation and access Machine Prog: Procedure calls Machine Prog: Structure, Memory Layout Machine Prog: Buffer Overflow Code optimizations Virtual memory: Address Spaces/ Translation, Goal Virtual memory: Page table/physcial to virtual Process Dynamic Memory Allocation I: malloc, free Dynamic Memory Allocation II: design allocator Dynamic Memory Allocation III: futher optimization Concurrent Programming I: thread, race Concurrent Programming II: lock Concurrent Programming III: conditional variable Concurrent Programming IV: Other primitives Basic (Easy) Advanced (Hard)
Bits, Bytes, Ints, Word Zhaoguo Wang
Bit 0 /
The world has moved away from analog signal to Analog signals: smooth and continuous Problems. Difficult to design 2. Susceptible to noise Analog components: resistors, capacitors, inductors, diodes, e.t.c
to digital 0 0 0 0 0 0 Digital signals: discrete (encode sequence of 0s and s) Advantages Digital components: transistors, logic gates. Easier to design Simple Integrate millions on a single chip 2. Reliable Robust to noise
Using bits to represent everything A bit is too small to be much used In English, there are 26 characters and plenty words in the vocabulary Using bits instead of bit Group bits together Apply some interpretation to the different possible bit patterns Represent elements of any limit set
Represent nonnegative integer bits: b n- b n-2 b 2 b b 0 b i : bit b in i-th position (from right to left) 0 <= i < n b * 2 i (b is 0 or ) Bits 000 Value 0*2 4 +*2 3 +0*2 2 +*2 +0*2 0 = 0 Bits 000 Value?
Represent nonnegative integer bits: b n- b n-2 b 2 b b 0 b i : bit b in i-th position (from right to left) 0 <= i < n b * 2 i (b is 0 or ) Bits 000 Value 0*2 4 +*2 3 +0*2 2 +*2 +0*2 0 = 0 Bits 000 Value 28
Most significant bit (MSB) The bit position has the greatest value Bits 000 MSB? Bits 000 MSB?
Most significant bit (MSB) The bit position has the greatest value The leftmost bit Bits 000 MSB 0 Bits 000 MSB
Least significant bit (LSB) The bit position has the least value The rightmost bit Bits 000 MSB 0 Bits 000 MSB 0
Your Mental Model 0 0 0 CPU Arithmetic Logic Unit Memory Memory is a continuous array. Each unit of the array has one bit.
Your Mental Model 0 0 0 * 2 7 CPU Arithmetic Logic Unit Memory
Your Mental Model 0 0 0 * 2 7 + * 2 6 CPU Arithmetic Logic Unit Memory
Your Mental Model 0 0 0 CPU Arithmetic Logic Unit * 2 7 + * 2 6 + 0 * 2 5 Memory
Your Mental Model 0 0 0 CPU Arithmetic Logic Unit * 2 7 + * 2 6 + 0 * 2 5 + * 2 4 Memory
Your Mental Model 0 0 0 CPU Arithmetic Logic Unit * 2 7 + * 2 6 + 0 * 2 5 + * 2 4 + * 2 3 Memory
Your Mental Model 0 0 0 CPU Arithmetic Logic Unit * 2 7 + * 2 6 + 0 * 2 5 + * 2 4 + * 2 3 + * 2 2 Memory
Your Mental Model 0 0 0 CPU Arithmetic Logic Unit * 2 7 + * 2 6 + 0 * 2 5 + * 2 4 + * 2 3 + * 2 2 + * 2 Memory
Your Mental Model 0 0 0 CPU Arithmetic Logic Unit * 2 7 + * 2 6 + 0 * 2 5 + * 2 4 + * 2 3 + * 2 2 + * 2 + 0 Memory
Your Mental Model 0 0 0 Memory CPU Arithmetic Logic Unit * 2 7 + * 2 6 + 0 * 2 5 + * 2 4 + * 2 3 + * 2 2 + * 2 + 0 Low efficiency
Byte Each memory unit has multiple bits Dr. Werner Buchholz in July 956 Byte sizes from bit to 48 bits have been used in the history
Byte Each memory unit has multiple bits Dr. Werner Buchholz in July 956 Byte sizes from bit to 48 bits have been used in the history 00 0 00 00 000 0000 000 00 CPU Arithmetic Logic Unit Memory is a continuous array. Each unit is a byte. Memory
Byte 8 bits chunk IBM System/360, 964 Introduce Intel 8080, 974 Modern processors Widely adopted Standard
Your current mental model Bits 000 0000 00000 00000 addresses addr addr 2 addr 3 addr 4 000 0000 00000 00000... Memory addr 000 Each byte has 8 bits CPU Arithmetic Logic Unit
Your current mental model Bits 000 0000 00000 00000 addresses addresses addr 4 addr 3 addr 2 addr 00000 00000 0000 000... Memory addr 000 Each byte has 8 bits CPU Arithmetic Logic Unit
Range of Single Byte Maximum Minimum
Range of Single Byte Maximum 2 à 255 Minimum
Range of Single Byte Maximum 2 à 255 Minimum 00000000 2 à 0
Bit pattern description intuitive way Binary notation Bits 000 0000 00000 00000 4 bytes
Bit pattern description intuitive way Binary notation Too verbose Bits 000 0000 00000 00000 4 bytes 5 cm on my laptop
Bit pattern description strawman Decimal Notation 3 decimal digits to represent one byte Bits 000 0000 00000 00000 Decimal 74 202 04 026
Bit pattern description strawman Decimal Notation 3 decimal digits to represent one byte Bits 000 0000 00000 00000 Decimal 74 202 04 026 too tedious to do the conversion
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers
Hexadecimal Notation Byte / 8 bits Binary: 00000000 2 to 2 Decimal: 0 0 to 255 0 Hex: 00 6 to FF 6 0 0 0000 000 2 2 000 3 3 00 4 4 000 5 5 00 6 6 00 7 7 0 8 8 000 9 9 00 A 0 00 B 0 C 2 00 D 3 0 E 4 0 F 5
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex Hex(C) 00 =
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A Hex(C) 00 = * 2 3 + 0 * 2 2 + * 2 + 0 = 0 = A 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A Hex(C) 0 =
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E Hex(C) 0 = * 2 3 + * 2 2 + * 2 + 0 = 4 = E 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E Hex(C) 00 =
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C Hex(C) 00 = * 2 3 + * 2 2 + 0 * 2 + 0 = 2 = C 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C Hex(C) 00 =
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C A Hex(C) 00 = * 2 3 + 0 * 2 2 + * 2 + 0 = 0 = A 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C A 0 Hex(C) 0000 = 0 * 2 3 + 0 * 2 2 + 0 * 2 + 0 = 0 = 0 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C A 0 E Hex(C) 0 = * 2 3 + * 2 2 + * 2 + 0 = 4 = E 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C A 0 E Hex(C) 000 = 0 * 2 3 + 0 * 2 2 + 0 * 2 + = = 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C A 0 E A Hex(C) 00 = * 2 3 + 0 * 2 2 + * 2 + 0 = 0 = A 6
Hexadecimal Notation Write bit patterns as base-6 (hex) numbers 0-9 and a-f (0-5) Each number can represent a 4 bits chunk Each byte is represented with 2 hex numbers (00 6 -- FF 6 ) Bits 000 0000 00000 00000 Decimal 74 202 04 026 Hex A E C A 0 E A Hex(C) 0xAECA0EA
Exercises Time Hexadecimal Decimal Binary 0xBC 0xF3 55 00 0 00 0
Answers Hexadecimal Decimal Binary 0xA7 0*6 + 7 = 67 00 0 0x3E 3*6 + 4 = 62 00 0 0xBC *6 + 2 = 88 0 00 0x37 3*6+7=55 00 0 0xF3 5*6+3=243 00
Unsigned addition + 0 0xB + 0xA 00000 2 + 000000 2
Unsigned addition + 0 0xB + 0xA 00000 2 + 000000 2 0 0 0 0 0 + 0 0 0 0 0 0
Unsigned addition + 0 0xB + 0xA 00000 2 + 000000 2 0 0 0 0 0 + 0 0 0 0 0 0
Unsigned addition + 0 0xB + 0xA 00000 2 + 000000 2 0 0 0 0 0 + 0 0 0 0 0 0 2
Unsigned addition + 0 0xB + 0xA 00000 2 + 000000 2 0 0 0 0 0 + 0 0 0 0 0 0 0
Unsigned addition + 0 0xB + 0xA 00000 2 + 000000 2 0 0 0 0 0 + 0 0 0 0 0 0 0
Unsigned addition + 0 0xB + 0xA 00000 2 + 000000 2 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0
Unsigned subtraction - 0 0xB - 0xA 00000 2-000000 2 0 0 0 0 0-0 0 0 0 0 0 0 0 0 0 0 0 0
Unsigned subtraction - 0 0xB - 0xA 00000 2-000000 2 0 0 0 0 0-0 0 0 0 0 0 0 0 0 0 0 0 0
Unsigned subtraction 0-0xA 0xB 000000 2-00000 2 0 0 0 0 0 0-0 0 0 0 0???
Question N: How to represent negative numbers?
Strawman Most significant bit (MSB) represent the sign 0 0 0 0 0 0 0 2 0 0 0 0 0 0 2-0 0 0 0 0 0 0 + 0 0 0 0 0 0
Strawman Most significant bit (MSB) represent the sign 0 0 0 0 0 0 0 2 0 0 0 0 0 0 2-0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0
Strawman Most significant bit (MSB) represent the sign 0 0 0 0 0 0 0 2 0 0 0 0 0 0 2-0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0-2???
Two s complement Byte 0000 Unsigned number * 2 7 + 0 * 2 6 + 0 * 2 5 + * 2 4 + 0 * 2 3 + * 2 2 + * 2 + 0 * 2 0
Two s complement Byte 0000 Unsigned number * 2 7 + 0 * 2 6 + 0 * 2 5 + * 2 4 + 0 * 2 3 + * 2 2 + * 2 + 0 * 2 0 Signed number - * 2 7 + 0 * 2 6 + 0 * 2 5 + * 2 4 + 0 * 2 3 + * 2 2 + * 2 + 0 * 2 0
Two s complement b! = [ b w, b w,..., b ] 0 val! b w i=0 ( ) = b w 2 w + b i 2 i MSB: val( b w ) = -b w * 2w Other: val ( b i ) = b i * 2i, 0 <= i < w
Two s complement b! = [ b w, b w,..., b ] 0 val! b w i=0 ( ) = b w 2 w + b i 2 i Binary 000 000 00 00 00 00 Value
Two s complement b! = [ b w, b w,..., b ] 0 val! b w i=0 ( ) = b w 2 w + b i 2 i Binary Value 000 000 - * 2 7 + -27 00 00 00 00
Two s complement b! = [ b w, b w,..., b ] 0 val! b w i=0 ( ) = b w 2 w + b i 2 i Binary Value 000 000 - * 2 7 + -27 00 00 - * 2 7 + 2 5 + 2 2 + 2 0-9 00 00
Two s complement b! = [ b w, b w,..., b ] 0 val! b w i=0 ( ) = b w 2 w + b i 2 i Binary Value 000 000 - * 2 7 + -27 00 00 - * 2 7 + 2 5 + 2 2 + 2 0-9 00 00 2 6 + 2 4 + 2 2 + 2 85
Two s complement b! = [ b w, b w,..., b ] 0 val! b w i=0 ( ) = b w 2 w + b i 2 i 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0
Two s complement b! = [ b w, b w,..., b ] 0 val! b w i=0 ( ) = b w 2 w + b i 2 i 0 0 0 0 0 0 0 2 0 + 0 0 0 0 0 0 - * 2 7 + 2 0-27 0 0 0 0 0 0 - * 2 7 + 2-26
Find 2 s complement quickly With a negative number, how to give its binary representation? e.g. -40
Find 2 s complement quickly With a negative number, how to give its binary representation? e.g. -40 Step. represent 40 in binary 000 000
Find 2 s complement quickly With a negative number, how to give its binary representation? e.g. -40 Step 2. flip all bits 000 000 0 0
Find 2 s complement quickly With a negative number, how to give its binary representation? e.g. -40 Step 3. add 000 000 0 0 0 000
Find 2 s complement quickly With a negative number, how to give its binary representation? e.g. -40 Step 3. add 000 000 0 0 0 000 + 000 000 0 0
Find 2 s complement quickly With a negative number, how to give its binary representation? e.g. -40 Step 3. add 000 000 0 0 0 000 000 000 0 0 + 0000 0000
Exercise Time II Hexadecimal Decimal Binary 0xce 27-28 -90 00 00
Answers Hexadecimal Decimal Binary 0xce -50 00 0 0x9c -00 00 00 0x7f 27 0 0x80-28 000 0000 0xa6-90 00 00
Ranges Range Min Max byte unsigned [0, 2 8 ] 0 255 byte signed
Ranges Range Min Max byte unsigned [0, 2 8 ] 0 255 byte signed [-2 7, 2 7 ] -28 27 Min: 000 0000 Max: 0
Overflow + 0 0 0 0 0 0 0 0 0 0 0 0-27 -27 Range Min Max byte unsigned [0, 2 8 ] 0 255 byte signed [-2 7, 2 7 ] -28 27
Overflow + 0 0 0 0 0 0 0 0 0 0 0 0-27 -27 2??? 0 0 0 0 0 0 0 Range Min Max byte unsigned [0, 2 8 ] 0 255 byte signed [-2 7, 2 7 ] -28 27
Intel 8080 0xb0 0xa9 0xa8 0xa7 0xa6 0xa5 0xa4 0xa3 0xa2 0xa 0x0f 0xaf 0xe 0x4c 0xea 0xcb 0xba 0x00 0xff 0x8c 0x4c CPU Arithmetic Logic Unit registers 0x4c Memory
Intel 8080 0xb0 0xa9 0xa8 0xa7 0xa6 0xa5 0xa4 0xa3 0xa2 0xa 0x0f 0xaf 0xe 0x4c 0xea 0xcb 0xba 0x00 0xff 0x8c Memory 0x4c CPU Arithmetic Logic Unit registers 0x4c 8 bits machine 8 bits length of Memory processor transfer CPU Register Memory Address Instruction
Intel 386 0x000000b0 0x000000a9 0x000000a8 0x000000a7 0x000000a6 0x000000a5 0x000000a4 0x000000a3 0x000000a2 0x000000a 0x0f 0xaf 0xe 0x4c 0xea 0xcb 0xba 0x00 0xff 0x8c Memory 0x4ceaf0f CPU Arithmetic Logic Unit registers 0x4ceaf0f 32 bits machine 32 bits length of Memory processor transfer CPU Register Memory Address Instruction
Intel Opteron à i7 0x00 00b0 0x00 00a9 0x00 00a8 0x00 00a7 0x00 00a6 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x0f 0xaf 0xe 0x4c 0xea 0xcb 0xba 0x00 0xff 0x8c Memory 0x00bacbea4ceaf0f CPU Arithmetic Logic Unit registers 0x00bacbea4ceaf0f 64 bits machine 64 bits length of Memory processor transfer CPU Register Memory Address Instruction
Intel Opteron à i7 0x00 00b0 0x00 00a9 0x00 00a8 0x00 00a7 0x00 00a6 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x0f 0xaf 0xe 0x4c 0xea 0xcb 0xba 0x00 0xff 0x8c Memory 0x00bacbea4ceaf0f CPU Arithmetic Logic Unit registers 0x00bacbea4ceaf0f Word Memory processor transfer CPU Register Memory Address Instruction
Word Definition Fixed size of data handled as a unit by the instruction set or processor Length 8 for 8 bits machine 32 for 32 bits machine 64 for 64 bits machine
Integral data types on 64 bits machine Length Min Max [signed] char byte -2 7 2 7 - unsigned char byte 0 2 8 - short 2 bytes unsigned short 2 bytes int 4 bytes unsigned int 4 bytes long 8 bytes unsigned long 8 bytes
Integral data types on 64 bits machine Length Min Max [signed] char byte -2 7 2 7 - unsigned char byte 0 2 8 - short 2 bytes -2 5 2 5 - unsigned short 2 bytes 0 2 6 - int 4 bytes unsigned int 4 bytes long 8 bytes unsigned long 8 bytes
Integral data types on 64 bits machine Length Min Max [signed] char byte -2 7 2 7 - unsigned char byte 0 2 8 - short 2 bytes -2 5 2 5 - unsigned short 2 bytes 0 2 6 - int 4 bytes -2 3 2 3 - unsigned int 4 bytes 0 2 32 - long 8 bytes unsigned long 8 bytes
Integral data types on 64 bits machine Length Min Max [signed] char byte -2 7 2 7 - unsigned char byte 0 2 8 - short 2 bytes -2 5 2 5 - unsigned short 2 bytes 0 2 6 - int 4 bytes -2 3 2 3 - unsigned int 4 bytes 0 2 32 - long 8 bytes -2 63 2 63 - unsigned long 8 bytes 0 2 64 -
Memory layout 0x00 00b0 0x00 00a9 0x00 00a8 CPU Arithmetic Logic Unit 0x00 00a7 0x00 00a6 registers 0x00 00a5 0x00 00a4 0x00 00a3 int a = 0x2345678 0x00 00a2 0x00 00a int a address: 0x00 00a2 Memory
Memory layout Intuition 0x00 00b0 0x00 00a9 0x00 00a8 CPU Arithmetic Logic Unit 0x00 00a7 0x00 00a6 registers 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x78 0x56 0x34 0x2 int a int a = 0x2345678 address: 0x00 00a2 Memory
Memory layout Little Endian 0x00 00b0 0x00 00a9 0x00 00a8 CPU Arithmetic Logic Unit 0x00 00a7 0x00 00a6 registers 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x2 0x34 0x56 0x78 Memory int a int a = 0x2345678 address: 0x00 00a2 Least significant byte in smallest address, e.g, laptops, and server machines
Advantages of Little Endian + 0x2345678 0x2345 Processor performs the calculation from the least significant bit Processor can simultaneously perform memory transfer and calculation.
Advantages of Little Endian 0x00 00b0 0x00 00a9 0x00 00a8 0x00 00a7 0x00 00a6 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a Memory CPU Arithmetic Logic Unit registers long a = 0x0000000090abcdef address: 0x00 00a2 long a
Advantages of Little Endian 0x00 00b0 0x00 00a9 0x00 00a8 0x00 00a7 0x00 00a6 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x00 0x00 0x00 0x00 0x90 0xab 0xcd 0xef Memory CPU Arithmetic Logic Unit registers long a = 0x0000000090abcdef address: 0x00 00a2 long a
Advantages of Little Endian 0x00 00b0 0x00 00a9 0x00 00a8 0x00 00a7 0x00 00a6 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x00 0x00 0x00 0x00 0x90 0xab 0xcd 0xef Memory CPU Arithmetic Logic Unit registers long a = 0x0000000090abcdef address: 0x00 00a2 long a int b = (int)a Directly get the data from 0x00 00a2
Memory layout Intuition 0x00 00b0 0x00 00a9 0x00 00a8 CPU Arithmetic Logic Unit 0x00 00a7 0x00 00a6 registers 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x78 0x56 0x34 0x2 int a int a = 0x2345678 address: 0x00 00a2 Is this wrong? Memory
Memory layout Intuition 0x00 00b0 0x00 00a9 0x00 00a8 CPU Arithmetic Logic Unit 0x00 00a7 0x00 00a6 registers 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x78 0x56 0x34 0x2 int a int a = 0x2345678 address: 0x00 00a2 Is this wrong? Memory
Memory layout Big Endian 0x00 00b0 0x00 00a9 0x00 00a8 0x00 00a7 0x00 00a6 0x00 00a5 0x00 00a4 0x00 00a3 0x00 00a2 0x00 00a 0x78 0x56 0x34 0x2 Memory int a CPU Arithmetic Logic Unit registers int a = 0x2345678 address: 0x00 00a2 Most significant byte in smallest address, e.g, ARM architecture >v3 (cellphones, ipads)
Advantages of Big Endian. Easy to read 2. Test whether the number is positive or negative by looking at the byte at offset zero.