Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jensendarren/47410ee0c4d0223330f6c847b6bda666 to your computer and use it in GitHub Desktop.
Save jensendarren/47410ee0c4d0223330f6c847b6bda666 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract IntegerType {
// uint type is same as uint256
uint256 aUint;
// int type is same as int256
int256 anInt;
/* uint8 range 0 to 2 ** 8 - 1 */
uint8 public aUint8Default;
uint8 public aUint8 = 123;
// too high uint8
uint8 aUint8OutOfBounds = 255;
/* uint16 range 0 to 2 ** 16 - 1 */
uint16 aUint16;
/* int8 ranges from -2 ** 7 - 1 to 2 ** 7 - 1 */
int8 anInt8;
/* int16 ranges from -2 ** 15 to 2 ** 15 - 1 */
int16 anInt16;
// type only available in incremenets of 8 bits
uint24 public notAvailable;
// minimum and maximum of int8
int8 public minInt8 = type(int8).min;
int8 public maxInt8 = type(int8).max;
// calculate min / max
int8 public minInt8Calculated = - 2 ** 7; // - 128
int8 public maxInt8Calculated = 2 ** 7 - 1; // 127
// minimum and maximum of uint8
uint8 public minUint8 = type(uint8).min;
uint8 public maxUint8 = type(uint8).max;
// calculate max uint8 (min is 0)
uint8 public maxUint8Calculated = 2 ** 8 - 1; // 255
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment