5.1.11 · D3 · HinglishInstruction Set Architecture (ISA)

Worked examplesEndianness (big vs little)

2,561 words12 min read↑ Read in English

5.1.11 · D3 · Hardware › Instruction Set Architecture (ISA) › Endianness (big vs little)

Shuru karne se pehle, do symbols ka ek reminder jo hum poore time use karte hain.


Scenario matrix

Endianness choti lagti hai, lekin iske baare mein questions alag-alag cells mein aate hain. Neeche har class of case hai. Baad ke worked examples mein har ek tag karta hai ki woh kaunsa cell cover kar raha hai, aur saath mein poori grid fill ho jaati hai.

Cell Scenario class Kya tricky hai
C1 Ordinary 4-byte int, dono endians Baseline placement
C2 2-byte (16-bit) value Chhota — index range change hoti hai
C3 8-byte (64-bit) value Bada — bookkeeping stress
C4 Zero value 0x00000000 Degenerate: dono endians identical lagte hain
C5 Palindromic bytes jaise 0x12341234? (partial symmetry) Kaunse bytes actually move karte hain?
C6 Value jisme middle mein 0x00 / leading zeros hon Fewer bytes padhna; sign-of-location
C7 Negative int (two's complement, high bit set) Sign bit MSB mein hota hai — woh kahaan jaata hai?
C8 Ek char[] string (scalar nahi) Endianness apply nahi hoti — yeh trap hai
C9 Memory read karna → value (inverse direction) Bytes se reconstruct karo
C10 Cross-endian transmission (network byte order) Real-world word problem
C11 Type-punning twist: ek 4-byte int ko do 2-byte halves ki tarah padhna Exam-style; sub-word views
C12 Mixed-type struct memory mein laid out Har field independently endian-swap hota hai; padding

Ab hum sab walk karenge.


Worked examples

Baseline placement

Figure — Endianness (big vs little)

Alag-alag value sizes

Figure — Endianness (big vs little)
Figure — Endianness (big vs little)

Degenerate aur near-degenerate inputs

Figure — Endianness (big vs little)

Sign bit

Classic trap: strings scalars nahi hote

Inverse direction

Real-world word problem

Sub-word views (type-punning)

Mixed-type struct

Figure — Endianness (big vs little)

Coverage check

Recall Kya humne matrix ka har cell fill kiya?

C1 baseline ::: C1 example (0x0A0B0C0D) C2 16-bit ::: C2 example (0xBEEF) C3 64-bit ::: C3 example (0x11..88) C4 zero degenerate ::: C4 example (0x00000000) C5 partial symmetry ::: C5 example (0x12341234) C6 leading zeros / narrow read ::: C6 example (0x00000005) C7 negative / sign bit ::: C7 example (-2 = 0xFFFFFFFE) C8 string not scalar ::: C8 example ("Helo") C9 read back → value ::: C9 example (0x1234CDAB) C10 network transmission ::: C10 example (port 443) C11 sub-word type-pun ::: C11 example (0xAABBCCDD halves) C12 mixed-type struct ::: C12 example (a/b/c with padding)


Connections

  • Endianness — parent topic — woh core rule jise yeh examples exercise karte hain.
  • Data Representation decomposition jis par har example tika hai.
  • Memory Addressing — offsets aur low/high addresses jo poore use kiye hain.
  • Network Protocols — C10 ka big-endian "network byte order" aur htons.
  • Pointers and Type Punning — C11 ka sub-word reinterpretation aur C12 ka struct layout.
  • Bitwise Operations — shift/mask jo byte extraction implement karta hai.
  • Instruction Set Architecture (ISA) — CPU ek endianness commit karta hai.