From 6b6d109da725cb08671d523f6689dde52ebcf9dc Mon Sep 17 00:00:00 2001 From: Joshua Potter Date: Sun, 11 Feb 2024 07:57:30 -0700 Subject: [PATCH] Notes on endianness. --- .../plugins/obsidian-to-anki-plugin/data.json | 7 +- notes/_journal/2024-02-11.md | 10 +- notes/binary/endianness.md | 119 ++++++++++++++++++ notes/binary/hexadecimal.md | 2 +- notes/c/declarations.md | 16 +++ 5 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 notes/binary/endianness.md diff --git a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json index 4e92e41..50a8f6b 100644 --- a/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json +++ b/notes/.obsidian/plugins/obsidian-to-anki-plugin/data.json @@ -123,12 +123,12 @@ "_journal/2024-02-08.md": "19092bdfe378f31e2774f20d6afbfbac", "algorithms/sorting/selection-sort.md": "73a077a726afd376650d1bd9e2d0bed9", "algorithms/index 1.md": "6fada1f3d5d3af64687719eb465a5b97", - "binary/hexadecimal.md": "a9633bbc9b53cc8c16ce6e56022f62e0", + "binary/hexadecimal.md": "531ebb4b1b10a0ac60899164bc1c3f07", "binary/index.md": "a67b5d0c8ac53e076590f315cce22201", "_journal/2024-02-09.md": "a798d35f0b2bd1da130f7ac766166109", "c/types.md": "cf3e66e5aee58a94db3fdf0783908555", "logic/quantification.md": "b7cf646a8c33aa83f48ddc37c733fafb", - "c/declarations.md": "381bb6ddbecd369b78012112b3a8e5de", + "c/declarations.md": "6d80eca97506fae9a4a209a558d3aa84", "algorithms/sorting/bubble-sort.md": "16dad1016dc6555163e42ba20f1d152d", "_journal/2024-02-10.md": "562b01f60ea36a3c78181e39b1c02b9f", "_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-01.md": "3aa232387d2dc662384976fd116888eb", "_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": { "Basic": [ diff --git a/notes/_journal/2024-02-11.md b/notes/_journal/2024-02-11.md index ec2be51..2d02064 100644 --- a/notes/_journal/2024-02-11.md +++ b/notes/_journal/2024-02-11.md @@ -2,10 +2,12 @@ title: "2024-02-11" --- -- [ ] Anki Flashcards -- [ ] KoL -- [ ] Sheet Music (10 min.) +- [x] Anki Flashcards +- [x] KoL +- [x] Sheet Music (10 min.) - [ ] OGS (1 Life & Death Problem) - [ ] Korean (Read 1 Story) - [ ] Interview Prep (1 Practice Problem) -- [ ] Log Work Hours (Max 3 hours) \ No newline at end of file +- [ ] Log Work Hours (Max 3 hours) + +* Notes on endianness. \ No newline at end of file diff --git a/notes/binary/endianness.md b/notes/binary/endianness.md new file mode 100644 index 0000000..901feea --- /dev/null +++ b/notes/binary/endianness.md @@ -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. + +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. + +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. + +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. + +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. + +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. + +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. + +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. + +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 + +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 + +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. + +END%% + +```c +#include +#include + +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. \ No newline at end of file diff --git a/notes/binary/hexadecimal.md b/notes/binary/hexadecimal.md index c4cd8ee..357a2ed 100644 --- a/notes/binary/hexadecimal.md +++ b/notes/binary/hexadecimal.md @@ -224,4 +224,4 @@ END%% ## 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. diff --git a/notes/c/declarations.md b/notes/c/declarations.md index 98a94ad..70dcceb 100644 --- a/notes/c/declarations.md +++ b/notes/c/declarations.md @@ -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. 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. + +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. + +END%% + %%ANKI Cloze `char` *typically* represents {1} byte(s) on a 64-bit platform.