Skip to content

Commit

Permalink
📝 bytes and string.
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfps committed May 10, 2024
1 parent de2bab2 commit 24e59de
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# uint8, uint128, uint256
# `uint8`, `uint128`, `uint256`

Unsigned integers are stored in memory based on the size of bytes they have. While sm all uint values like uint8 have 1 byte, uint256 has 32 bytes. Solidity's storage is designed in such a way that it can contain up to 32 bytes of value in one slot. In a situation where a variable doesn't contain up to 32 bytes, the value is stored and the next variable will be **packed** into the same slot, on the condition that when the bytes are added to the slot, it doesn't exceed 32 bytes.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# bytes1, bytes16, bytes32
# `bytes1`, `bytes16`, `bytes32`

`bytes[n]` are fixed length byte arrays, as opposed to `bytes` that are variable length byte arrays. The storage of `bytes[n]` in storage is such that it takes up a slot when it is of `bytes32` and is packed in cases of bytes below `32`. It is very similar to the `uint` type.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# bytes
# `bytes`

`bytes` are dynamic byte arrays. While the length of a `bytes[n]` is known as `n`, bytes do not have a specific
length and can stretch up to `128` or even more.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# string
# `string`

`string` are first converted into its `bytes` type by converting each individual ASCII character to its hexadecimal
`string` is first converted into its `bytes` type by converting each individual ASCII character to its hexadecimal
value. It is then stored in the exact way `bytes` are stored.

Example, a `string` type, `"hello"` would be first converted into `0x68656c6c6f`, and then stored just the way
Example, a `string` type, `"hello"` would be first converted into `0x68656c6c6f`, a concatenation of each hexadecimal value of each character, and then stored just the way
`bytes` are stored.

To get a knowledge of what the hexadecimal values of ASCII characters are, you can look up this table at
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `address`

0 comments on commit 24e59de

Please sign in to comment.