Skip to content

Commit

Permalink
perf(intro): add ascii table
Browse files Browse the repository at this point in the history
  • Loading branch information
tolstenko committed Sep 7, 2023
1 parent 61145bf commit 6cd497c
Show file tree
Hide file tree
Showing 2 changed files with 157 additions and 4 deletions.
4 changes: 2 additions & 2 deletions courses/artificialintelligence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Relevant dates for the Fall 2023 semester:
---

- Week 1. 2023/08/28
- Topic: [Introduction](https://docs.google.com/presentation/d/1OBEY-tb_ubgoq6Mk9lEsCFaYLINni3oPwjH8iAXEQQM/edit?usp=sharing)
- Topic: Introduction
- Formal Assignment: [Flocking at Beecrowd](assignments/flocking/README.md)
- Interactive Assignment: [Flocking at MoBaGEn](https://github.com/InfiniBrains/mobagen/tree/master/examples/flocking)

Expand All @@ -27,7 +27,7 @@ Relevant dates for the Fall 2023 semester:
---

- Week 2. 2023/09/04
- Topic: Behavioral agents
- Topic: [Flocking](https://docs.google.com/presentation/d/1OBEY-tb_ubgoq6Mk9lEsCFaYLINni3oPwjH8iAXEQQM/edit?usp=sharing)
- Formal Assignment: [Flocking at Beecrowd](assignments/flocking/README.md)
- Interactive Assignment: [Flocking at MoBaGEn](https://github.com/InfiniBrains/mobagen/tree/master/examples/flocking)

Expand Down
157 changes: 155 additions & 2 deletions courses/intro/03-datatypes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,149 @@ Chars can be used to represent letters following the [ascii table](https://www.a

A `char` can have different sizes to represent different character coding for different languages. If you are using hebrew, chinese, or others, you probably will need more than 1 byte to represent the chars. Use `char8_t` (UTF8), `char16_t`(UTF16) or `char36_t`(UTF32), to cover your character encoding for the language you are using.

##### ASCII table

ASCII - American Standard Code for Information Interchange - maps a number to a character. It is used to represent letters, digits and symbols. It is a standard that is used by most of the computers in the world.

It is a 7 bit table, so it can represent `2^7` or `128` different characters. The first 32 characters are control characters and the rest are printable characters. [Reference](https://en.cppreference.com/w/cpp/language/ascii). There are other tables that extend the ASCII table to 8 bits, or even 16 bits.

The printable chacacters starts at number 32 and goes up to 126. The first 32 characters are control characters and the rest are printable.

| Dec | Hex | Binary | Representation |
|---------------|------|-----------|-------------------------------------|
| 0 | 0x00 | 0000 0000 | `NUL` (`null`) |
| 1 | 0x01 | 0000 0001 | `SOH` (`start of heading`) |
| 2 | 0x02 | 0000 0010 | `STX` (`start of text`) |
| 3 | 0x03 | 0000 0011 | `ETX` (`end of text`) |
| 4 | 0x04 | 0000 0100 | `EOT` (`end of transmission`) |
| 5 | 0x05 | 0000 0101 | `ENQ` (`enquiry`) |
| 6 | 0x06 | 0000 0110 | `ACK` (`acknowledge`) |
| 7 | 0x07 | 0000 0111 | `BEL` (`bell`) |
| 8 | 0x08 | 0000 1000 | `BS` (`backspace`) |
| 9 | 0x09 | 0000 1001 | `HT` (`horizontal tab`) |
| 10 | 0x0A | 0000 1010 | `LF` (`NL` line feed, `new line`) |
| 11 | 0x0B | 0000 1011 | `VT` (`vertical tab`) |
| 12 | 0x0C | 0000 1100 | `FF` (`NP` form feed, `new page`) |
| 13 | 0x0D | 0000 1101 | `CR` (`carriage return`) |
| 14 | 0x0E | 0000 1110 | `SO` (`shift out`) |
| 15 | 0x0F | 0000 1111 | `SI` (`shift in`) |
| 16 | 0x10 | 0001 0000 | `DLE` (`data link escape`) |
| 17 | 0x11 | 0001 0001 | `DC1` (`device control 1`) |
| 18 | 0x12 | 0001 0010 | `DC2` (`device control 2`) |
| 19 | 0x13 | 0001 0011 | `DC3` (`device control 3`) |
| 20 | 0x14 | 0001 0100 | `DC4` (`device control 4`) |
| 21 | 0x15 | 0001 0101 | `NAK` (`negative acknowledge`) |
| 22 | 0x16 | 0001 0110 | `SYN` (`synchronous idle`) |
| 23 | 0x17 | 0001 0111 | `ETB` (`End of Transmission Block`) |
| 24 | 0x18 | 0001 1000 | `CAN` (`cancel`) |
| 25 | 0x19 | 0001 1001 | `EM` (`end of medium`) |
| 26 | 0x1A | 0001 1010 | `SUB` (`substitute`) |
| 27 | 0x1B | 0001 1011 | `ESC` (`escape`) |
| 28 | 0x1C | 0001 1100 | `FS` (`file separator`) |
| 29 | 0x1D | 0001 1101 | `GS` (`group separator`) |
| 30 | 0x1E | 0001 1110 | `RS` (`record separator`) |
| 31 | 0x1F | 0001 1111 | `US` (`unit separator`) |
| 32 | 0x20 | 0010 0000 | `space` (empty space) |
| 33 | 0x21 | 0010 0001 | `!` |
| 34 | 0x22 | 0010 0010 | `"` |
| 35 | 0x23 | 0010 0011 | `#` |
| 36 | 0x24 | 0010 0100 | `$` |
| 37 | 0x25 | 0010 0101 | `%` |
| 38 | 0x26 | 0010 0110 | `&` |
| 39 | 0x27 | 0010 0111 | `'` |
| 40 | 0x28 | 0010 1000 | `(` |
| 41 | 0x29 | 0010 1001 | `)` |
| 42 | 0x2A | 0010 1010 | `*` |
| 43 | 0x2B | 0010 1011 | `+` |
| 44 | 0x2C | 0010 1100 | `,` |
| 45 | 0x2D | 0010 1101 | `-` |
| 46 | 0x2E | 0010 1110 | `.` |
| 47 | 0x2F | 0010 1111 | `/` |
| 48 | 0x30 | 0011 0000 | `0` |
| 49 | 0x31 | 0011 0001 | `1` |
| 50 | 0x32 | 0011 0010 | `2` |
| 51 | 0x33 | 0011 0011 | `3` |
| 52 | 0x34 | 0011 0100 | `4` |
| 53 | 0x35 | 0011 0101 | `5` |
| 54 | 0x36 | 0011 0110 | `6` |
| 55 | 0x37 | 0011 0111 | `7` |
| 56 | 0x38 | 0011 1000 | `8` |
| 57 | 0x39 | 0011 1001 | `9` |
| 58 | 0x3A | 0011 1010 | `:` |
| 59 | 0x3B | 0011 1011 | `;` |
| 60 | 0x3C | 0011 1100 | `<` |
| 61 | 0x3D | 0011 1101 | `=` |
| 62 | 0x3E | 0011 1110 | `>` |
| 63 | 0x3F | 0011 1111 | `?` |
| 64 | 0x40 | 0100 0000 | `@` |
| 65 | 0x41 | 0100 0001 | `A` |
| 66 | 0x42 | 0100 0010 | `B` |
| 67 | 0x43 | 0100 0011 | `C` |
| 68 | 0x44 | 0100 0100 | `D` |
| 69 | 0x45 | 0100 0101 | `E` |
| 70 | 0x46 | 0100 0110 | `F` |
| 71 | 0x47 | 0100 0111 | `G` |
| 72 | 0x48 | 0100 1000 | `H` |
| 73 | 0x49 | 0100 1001 | `I` |
| 74 | 0x4A | 0100 1010 | `J` |
| 75 | 0x4B | 0100 1011 | `K` |
| 76 | 0x4C | 0100 1100 | `L` |
| 77 | 0x4D | 0100 1101 | `M` |
| 78 | 0x4E | 0100 1110 | `N` |
| 79 | 0x4F | 0100 1111 | `O` |
| 80 | 0x50 | 0101 0000 | `P` |
| 81 | 0x51 | 0101 0001 | `Q` |
| 82 | 0x52 | 0101 0010 | `R` |
| 83 | 0x53 | 0101 0011 | `S` |
| 84 | 0x54 | 0101 0100 | `T` |
| 85 | 0x55 | 0101 0101 | `U` |
| 86 | 0x56 | 0101 0110 | `V` |
| 87 | 0x57 | 0101 0111 | `W` |
| 88 | 0x58 | 0101 1000 | `X` |
| 89 | 0x59 | 0101 1001 | `Y` |
| 90 | 0x5A | 0101 1010 | `Z` |
| 91 | 0x5B | 0101 1011 | `[` |
| 92 | 0x5C | 0101 1100 | `\` |
| 93 | 0x5D | 0101 1101 | `]` |
| 94 | 0x5E | 0101 1110 | `^` |
| 95 | 0x5F | 0101 1111 | `_` |
| 96 | 0x60 | 0110 0000 | ``` ` ``` |
| 97 | 0x61 | 0110 0001 | `a` |
| 98 | 0x62 | 0110 0010 | `b` |
| 99 | 0x63 | 0110 0011 | `c` |
| 100 | 0x64 | 0110 0100 | `d` |
| 101 | 0x65 | 0110 0101 | `e` |
| 102 | 0x66 | 0110 0110 | `f` |
| 103 | 0x67 | 0110 0111 | `g` |
| 104 | 0x68 | 0110 1000 | `h` |
| 105 | 0x69 | 0110 1001 | `i` |
| 106 | 0x6A | 0110 1010 | `j` |
| 107 | 0x6B | 0110 1011 | `k` |
| 108 | 0x6C | 0110 1100 | `l` |
| 109 | 0x6D | 0110 1101 | `m` |
| 110 | 0x6E | 0110 1110 | `n` |
| 111 | 0x6F | 0110 1111 | `o` |
| 112 | 0x70 | 0111 0000 | `p` |
| 113 | 0x71 | 0111 0001 | `q` |
| 114 | 0x72 | 0111 0010 | `r` |
| 115 | 0x73 | 0111 0011 | `s` |
| 116 | 0x74 | 0111 0100 | `t` |
| 117 | 0x75 | 0111 0101 | `u` |
| 118 | 0x76 | 0111 0110 | `v` |
| 119 | 0x77 | 0111 0111 | `w` |
| 120 | 0x78 | 0111 1000 | `x` |
| 121 | 0x79 | 0111 1001 | `y` |
| 122 | 0x7A | 0111 1010 | `z` |
| 123 | 0x7B | 0111 1011 | `{` |
| 124 | 0x7C | 0111 1100 | `|` |
| 125 | 0x7D | 0111 1101 | `}` |
| 126 | 0x7E | 0111 1110 | `~` |
| 127 | 0x7F | 0111 1111 | `DEL` (`delete`) |

![](https://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/ASCII-Table-wide.svg/875px-ASCII-Table-wide.svg.png)

As you can imagine, this table is not enough to represent all the characters in the world(latin, chinese, japanese, etc). So there are other tables that extend the ASCII table to 8 bits, or even 16 bits.

#### Integer

!!! note
Expand Down Expand Up @@ -121,13 +264,23 @@ Enumerations can also have their underlying type explicitly specified:

```c++
enum class Color : char {
Red,
Red,
Green,
Blue
};
```
Here, the underlying type of the enumeration is `char`, so the constants `Red`, `Green`, and `Blue` will be stored as characters. The `enum class` syntax is known as a "scoped" enumeration, and it is recommended over the traditional `enum` syntax because it helps prevent naming conflicts. [See the CppCoreGuidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-enum) to understand better why you should prefer using this.
Here, the underlying type of the enumeration is `char`, so the constants `Red`, `Green`, and `Blue` will be stored as characters(1 byte size). The `enum class` syntax is known as a "scoped" enumeration, and it is recommended over the traditional `enum` syntax because it helps prevent naming conflicts. [See the CppCoreGuidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-enum) to understand better why you should prefer using this.
```c++
// You can make the value of the constants
// explicit to make your debugging easier:
enum class Color : char {
Red = 'r', //
Green = 'g',
Blue = 'b'
};
```

### Special derived type: string

Expand Down

0 comments on commit 6cd497c

Please sign in to comment.