> For the complete documentation index, see [llms.txt](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whs3-doge5k.gitbook.io/smartcontract-security-docs/basics/3.-evm/evm-2/undefined/uint8-bool-uint16-uint32-bytes1-32-enum.md).

# uint8, bool, uint16, uint32, bytes1\~32, enum

### **특징**

| 항목        | 내용                                                |
| --------- | ------------------------------------------------- |
| **타입명**   | 정적 타입 (크기 고정)                                     |
| **크기**    | 1바이트 \~ 수 바이트 (uint8: 1B, bool: 1B, uint16: 2B 등) |
| **패킹 가능** | O (32바이트 이내 여유 있음)                                |
| **저장 조건** | 연속 선언 + 슬롯 남은 공간 존재 + 중간에 큰 타입 없음                 |

***

### **예시 1**

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Example4 {
    uint8 public a;
    bool public b;
    uint16 public c;
    enum Status { OFF, ON }
    Status public s;

    constructor() {
      a = 3;
      b = true;
      c = 15;
      s = Status.ON;
    }
}
```

<figure><img src="https://2462457462-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLf9vwRuaws92ULgGvzTi%2Fuploads%2FxGvw9zMJYRfI5o6XPQ8O%2Fimage.png?alt=media&amp;token=2f7a94bd-e2d0-41fc-87be-577d4dd16e92" alt=""><figcaption></figcaption></figure>

```
// 스토리지

address: 0x0000000000000000000000000000000000000000000000000000000000000000
0x00000000000000000000000000000000000000000000000000000001000f0103
```

슬롯 0에 uint8, bool, uint16, enum 값이 패킹되었다.

* a = 0x03
* b = 0x01
* c = 0x000f
* d = 0x01

a(1 byte) + b(1 byte) + c(2 bytes) + d(1 byte)으로 총 5바이트가 하위 바이트부터 차례대로 슬롯 하나에 저장되었다.

***

### **예시 2**

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Example5 {
    uint8 public a;
    uint256 public b;
    bool public c;

    constructor() {
      a = 2;
      b = 3;
      c = true;
    }
}
```

<figure><img src="https://2462457462-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLf9vwRuaws92ULgGvzTi%2Fuploads%2FUAOnM3i8BXqD4fmdzghO%2Fimage.png?alt=media&amp;token=0683c4bd-dd4b-453c-9457-1fadb046216e" alt=""><figcaption></figcaption></figure>

```
// 스토리지

address: 0x0000000000000000000000000000000000000000000000000000000000000000
0x0000000000000000000000000000000000000000000000000000000000000002

address: 0x0000000000000000000000000000000000000000000000000000000000000001
0x0000000000000000000000000000000000000000000000000000000000000003

address: 0x0000000000000000000000000000000000000000000000000000000000000002
0x0000000000000000000000000000000000000000000000000000000000000001
```

슬롯 0, 1, 2에 각각 uint8, uint256, bool의 값이 저장되었다.

* a = 0x02
* b = 0x0000000000000000000000000000000000000000000000000000000000000003
* c = 0x01

패킹이 가능하지 않은 변수 타입이 중간에 선언된다면, uint, bool과 같이 패킹이 가능한 변수도 개별 슬롯에 저장된다.

***

### **Enum 추가 설명**

변수 타입 enum은 solidity에서 내부적으로 uint8로 표현된다. 따라서 0x00 형태로 나타낼 수 있고, 범위는 0\~255이다. 하나의 enum에는 256개까지 저장할 수 있고, 256을 넘어서 저장하면 컴파일 에러가 발생한다.

```solidity
enum Phase { Start, Progress, Done }
Phase public p = Phase.Start;
```

* Phase.Start = 0x00
* Phase.Progress = 0x01
* Phase.Done = 0x02
