Notes on endianness.
parent
49fbfb0ec5
commit
6b6d109da7
|
@ -123,12 +123,12 @@
|
||||||
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
|
"_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac",
|
||||||
"algorithms/sorting/selection-sort.md": "73a077a726afd376650d1bd9e2d0bed9",
|
"algorithms/sorting/selection-sort.md": "73a077a726afd376650d1bd9e2d0bed9",
|
||||||
"algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97",
|
"algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97",
|
||||||
"binary/hexadecimal.md": "a9633bbc9b53cc8c16ce6e56022f62e0",
|
"binary/hexadecimal.md": "531ebb4b1b10a0ac60899164bc1c3f07",
|
||||||
"binary/index.md": "a67b5d0c8ac53e076590f315cce22201",
|
"binary/index.md": "a67b5d0c8ac53e076590f315cce22201",
|
||||||
"_journal/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109",
|
"_journal/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109",
|
||||||
"c/types.md": "cf3e66e5aee58a94db3fdf0783908555",
|
"c/types.md": "cf3e66e5aee58a94db3fdf0783908555",
|
||||||
"logic/quantification.md": "b7cf646a8c33aa83f48ddc37c733fafb",
|
"logic/quantification.md": "b7cf646a8c33aa83f48ddc37c733fafb",
|
||||||
"c/declarations.md": "381bb6ddbecd369b78012112b3a8e5de",
|
"c/declarations.md": "6d80eca97506fae9a4a209a558d3aa84",
|
||||||
"algorithms/sorting/bubble-sort.md": "16dad1016dc6555163e42ba20f1d152d",
|
"algorithms/sorting/bubble-sort.md": "16dad1016dc6555163e42ba20f1d152d",
|
||||||
"_journal/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
|
"_journal/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
|
||||||
"_journal/2024-01/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970",
|
"_journal/2024-01/2024-01-31.md": "7c7fbfccabc316f9e676826bf8dfe970",
|
||||||
|
@ -142,7 +142,8 @@
|
||||||
"_journal/2024-02/2024-02-02.md": "a3b222daee8a50bce4cbac699efc7180",
|
"_journal/2024-02/2024-02-02.md": "a3b222daee8a50bce4cbac699efc7180",
|
||||||
"_journal/2024-02/2024-02-01.md": "3aa232387d2dc662384976fd116888eb",
|
"_journal/2024-02/2024-02-01.md": "3aa232387d2dc662384976fd116888eb",
|
||||||
"_journal/2024-02/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
|
"_journal/2024-02/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f",
|
||||||
"_journal/2024-02-11.md": "b8c72e835176c4b3e779e5243fc77b6b"
|
"_journal/2024-02-11.md": "438455de19ee8c76acce50a723612698",
|
||||||
|
"binary/endianness.md": "d73bf4e10385cdbc672d40a53f0fe868"
|
||||||
},
|
},
|
||||||
"fields_dict": {
|
"fields_dict": {
|
||||||
"Basic": [
|
"Basic": [
|
||||||
|
|
|
@ -2,10 +2,12 @@
|
||||||
title: "2024-02-11"
|
title: "2024-02-11"
|
||||||
---
|
---
|
||||||
|
|
||||||
- [ ] Anki Flashcards
|
- [x] Anki Flashcards
|
||||||
- [ ] KoL
|
- [x] KoL
|
||||||
- [ ] Sheet Music (10 min.)
|
- [x] Sheet Music (10 min.)
|
||||||
- [ ] OGS (1 Life & Death Problem)
|
- [ ] OGS (1 Life & Death Problem)
|
||||||
- [ ] Korean (Read 1 Story)
|
- [ ] Korean (Read 1 Story)
|
||||||
- [ ] Interview Prep (1 Practice Problem)
|
- [ ] Interview Prep (1 Practice Problem)
|
||||||
- [ ] Log Work Hours (Max 3 hours)
|
- [ ] Log Work Hours (Max 3 hours)
|
||||||
|
|
||||||
|
* Notes on endianness.
|
|
@ -0,0 +1,119 @@
|
||||||
|
---
|
||||||
|
title: Endianness
|
||||||
|
TARGET DECK: Obsidian::STEM
|
||||||
|
FILE TAGS: binary::endian
|
||||||
|
tags:
|
||||||
|
- binary
|
||||||
|
- endian
|
||||||
|
---
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
Platforms with multi-byte objects must establish the object's address and byte ordering. Objects are typically addressed by the smallest address of the bytes used. Bytes are ordered either in **big-endian** or **little-endian**. In big-endian, the most significant byte is listed first. In little-endian, the least significant byte is ordered first.
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
Platforms with multi-byte objects must establish what two conventions?
|
||||||
|
Back: The object's address and byte ordering.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283766-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How are multi-byte objects typically addressed?
|
||||||
|
Back: By the smallest address of the bytes used.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283768-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How are bytes of multi-byte objects typically ordered?
|
||||||
|
Back: As big-endian or little-endian.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283770-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What is endianness?
|
||||||
|
Back: The ordering of bytes of a multibyte object.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283771-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What does it mean for a byte to be "most significant"?
|
||||||
|
Back: It contribute most to the byte's (decimal) value.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283773-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What does it mean for a byte to be "least significant"?
|
||||||
|
Back: It contribute least to the byte's (decimal) value.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283774-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What does it mean to be big-endian?
|
||||||
|
Back: The most significant byte is ordered first.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283776-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What does it mean to be little-endian?
|
||||||
|
Back: The least significant byte is ordered first.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283777-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How are bytes of `int32_t x = 0x01234567` written in big-endian?
|
||||||
|
Back: `0x01 0x23 0x45 0x67`
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
Tags: c
|
||||||
|
<!--ID: 1707661283779-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How are bytes of `int32_t x = 0x01234567` written in little-endian?
|
||||||
|
Back: `0x67 0x45 0x23 0x01`
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
Tags: c
|
||||||
|
<!--ID: 1707661283780-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Cloze
|
||||||
|
Many microprocessors chips are {bi-endian} meaning they can be {configured as either big- or little-endian}.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707661283782-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
```c
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int32_t x = 0x01234567;
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
printf("%.2x ", ((unsigned char *)(&x))[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The above snippet can be used to check endianness on the current machine. If big-endian, the output should be `01 23 45 67`. If little-endian, `67 45 23 01`.
|
||||||
|
|
||||||
|
## Reference
|
||||||
|
|
||||||
|
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
|
@ -224,4 +224,4 @@ END%%
|
||||||
|
|
||||||
## Reference
|
## Reference
|
||||||
|
|
||||||
* Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
* Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
|
|
@ -36,6 +36,22 @@ Back: It can only represent nonnegative values.
|
||||||
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
END%%
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
How large is a word?
|
||||||
|
Back: This is a machine-dependent value.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707657889227-->
|
||||||
|
END%%
|
||||||
|
|
||||||
|
%%ANKI
|
||||||
|
Basic
|
||||||
|
What word sizes are typically nowadays?
|
||||||
|
Back: 32- and 64-bit word sizes.
|
||||||
|
Reference: Bryant, Randal E., and David O'Hallaron. *Computer Systems: A Programmer's Perspective*. Third edition, Global edition. Always Learning. Pearson, 2016.
|
||||||
|
<!--ID: 1707657889230-->
|
||||||
|
END%%
|
||||||
|
|
||||||
%%ANKI
|
%%ANKI
|
||||||
Cloze
|
Cloze
|
||||||
`char` *typically* represents {1} byte(s) on a 64-bit platform.
|
`char` *typically* represents {1} byte(s) on a 64-bit platform.
|
||||||
|
|
Loading…
Reference in New Issue