solidity0.8.0 常用数据类型

常用数据类型

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

// 常用变量
contract ValueType {
    // bool 默认值为 false
    bool public b = true;

    // uint 默认值为 0
    // 对于无符号的整数类型 uint,范围为 0 到 2^n - 1,其中 n 是位数。
    uint public u = 123; // uint = uint256 0 to 2**256 - 1
                         //        uint8   0 to 2**8 - 1
                         //        uint16  0 to 2**16 - 1
                         //        ... 以 8 的倍数增加
    
    // int 默认值为 0
    // 对于带符号的整数类型 int,范围为 -2^(n-1) 到 2^(n-1)-1,其中 n 是位数。
    int public i = -123; // int = int256   -2**255 to 2**255 - 1
                         //       int128   -2**127 to 2**127 - 1
    int public minInt = type(int).min;
    int public maxInt = type(int).max;

    // address默认值为 address(0) = 0x0000000000000000000000000000000000000000
    address public addr = 0xd9145CCE52D386f254917e481eB44e9943F39138;

    // bytes1 默认值为 0x00
    // bytes2 默认值为 0x0000
    // bytes3 默认值为 0x000000
    // 以此类推
    // bytes 最大是32个字节
    bytes32 public b32 = 0xd9145CCE52D386f254917e481eB44e9943F391384e9943F391384e9943F39138;
    
}
posted @ 2023-08-03 22:22  三省吾身~  阅读(31)  评论(0)    收藏  举报