Skip to main content
The int type in Dart is an immutable, non-fractional numeric data type that extends the abstract num class. It represents whole numbers and implements Comparable<num>, supporting standard arithmetic, relational, and bitwise operations.

Memory Representation and Platform Bounds

Dart’s underlying architecture dictates the memory footprint and limits of the int type based on the compilation target:
  • Dart Native (VM, JIT, and AOT): Represented as a 64-bit two’s complement integer. The representable range is 263-2^{63} to 26312^{63} - 1 (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807).
  • Dart Web (dart2js and dartdevc): Represented as a JavaScript Number, which is an IEEE 754 double-precision floating-point value. The safe integer range without precision loss is restricted to 253+1-2^{53} + 1 to 25312^{53} - 1 (-9,007,199,254,740,991 to 9,007,199,254,740,991). Exceeding these bounds on the web results in silent precision loss rather than a standard integer overflow.

Literal Syntax

Integer literals can be declared using standard decimal notation or hexadecimal notation prefixed with 0x or 0X.
int decimalValue = 42;
int negativeValue = -1024;
int hexValue = 0xDEADBEEF;

Parsing and Type Conversion

The int class provides static methods for string-to-integer conversion, supporting optional radix (base) parameters ranging from 2 to 36.
// Throws FormatException if parsing fails
int parsed = int.parse('42');

// Returns null if parsing fails (safe parsing)
int? safelyParsed = int.tryParse('42px'); 

// Parsing with a specific radix
int hexParsed = int.parse('FF', radix: 16); // 255
int binaryParsed = int.parse('1010', radix: 2); // 10

Bitwise Operations

Because int represents discrete bits, it fully supports bitwise manipulation. On the web, bitwise operations truncate the operands to 32-bit integers before evaluating.
int a = 5;  // 0101 in binary
int b = 3;  // 0011 in binary

int bitwiseAnd = a & b;      // 0001 (1)
int bitwiseOr = a | b;       // 0111 (7)
int bitwiseXor = a ^ b;      // 0110 (6)
int bitwiseNot = ~a;         // Bitwise NOT (one's complement), yields -6
int shiftLeft = a << 1;      // 1010 (10)
int shiftRight = a >> 1;     // 0010 (2)
int unsignedShift = a >>> 1; // Logical right shift (fills with 0)

Core Properties and Methods

The int class exposes several built-in getters and methods for mathematical evaluation and base conversion.
int value = -42;

// Parity evaluation
bool isEven = value.isEven; // true
bool isOdd = value.isOdd;   // false

// Mathematical properties
int sign = value.sign;      // -1 (Returns -1, 0, or 1)
int absolute = value.abs(); // 42

// Base conversion
String binaryString = absolute.toRadixString(2); // "101010"
String hexString = absolute.toRadixString(16);   // "2a"

// Division yielding an integer (truncating division)
int quotient = 10 ~/ 3; // 3
Tired of Poor Dart Skills? Fix That With Deep Grasping!Learn More