diff options
Diffstat (limited to 'lessons/src/lesson036_bit_arrays')
-rw-r--r-- | lessons/src/lesson036_bit_arrays/code.gleam | 13 | ||||
-rw-r--r-- | lessons/src/lesson036_bit_arrays/text.html | 26 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lessons/src/lesson036_bit_arrays/code.gleam b/lessons/src/lesson036_bit_arrays/code.gleam new file mode 100644 index 0000000..dc772ca --- /dev/null +++ b/lessons/src/lesson036_bit_arrays/code.gleam @@ -0,0 +1,13 @@ +import gleam/io + +pub fn main() { + // 8 bit int. In binary: 00000011 + io.debug(<<3>>) + io.debug(<<3>> == <<3:size(8)>>) + + // 16 bit int. In binary: 0001100000000011 + io.debug(<<6147:size(16)>>) + + // A bit array of UTF8 data + io.debug(<<"Hello, Joe!":utf8>>) +} diff --git a/lessons/src/lesson036_bit_arrays/text.html b/lessons/src/lesson036_bit_arrays/text.html new file mode 100644 index 0000000..3214db1 --- /dev/null +++ b/lessons/src/lesson036_bit_arrays/text.html @@ -0,0 +1,26 @@ +<p> + Bit arrays represent a sequence of 1s and 0s, and are a convenient syntax for + constructing and manipulating binary data. +</p> +<p> + Each segment of a bit array can be given options to specify the representation + used for that segment. +</p> +<ul> + <li><code>size</code>: the size of the segment in bits.</li> + <li><code>unit</code>: how many times to repeat the segment.</li> + <li><code>bits</code>: a nested bit array of any size.</li> + <li><code>bytes</code>: a nested byte-aligned bit array.</li> + <li><code>float</code>: a 64 bits floating point number.</li> + <li><code>int</code>: an int with a default size of 8 bits.</li> + <li><code>big</code>: big endian.</li> + <li><code>little</code>: little endian.</li> + <li><code>native</code>: the endianness of the processor.</li> + <li><code>utf8</code>: utf8 encoded text.</li> + <li><code>utf16</code>: utf16 encoded text.</li> + <li><code>utf32</code>: utf32 encoded text.</li> +</ul> +<p> + Bit arrays have limited support when compiling to JavaScript, not all options + can be used. Full bit array support will be implemented in future. +</p> |