The BigInt static parse() method parses the given string source as a, possibly signed, integer literal and returns its value.
The syntax of BigInt.parse() static-method is:
BigInt parse(String source, { int radix })
This parse() static-method of BigInt parses source
as a, possibly signed, integer literal and returns its value.
Parameter | Optional/Required | Description |
---|---|---|
source | required | the string to parse as an integer |
radix | optional | the base of the numeral system used in source (defaults to 10 if not provided) |
BigInt.parse() returns value of type BigInt
.
In this example,
numberStr
with the value '12345'.parse()
method to parse the string as an integer and store it in a BigInt variable number
.void main() {
String numberStr = '12345';
BigInt number = BigInt.parse(numberStr);
print('Parsed number: $number');
}
Parsed number: 12345
In this example,
charStr
with the value 'A'.parse()
method with a radix of 16 (hexadecimal) to parse the string as a hexadecimal integer and store it in a BigInt variable charCode
.void main() {
String charStr = 'A';
BigInt charCode = BigInt.parse(charStr, radix: 16);
print('Parsed character code: $charCode');
}
Parsed character code: 10
In this example,
binaryStr
with the value '1010'.parse()
method with a radix of 2 (binary) to parse the string as a binary integer and store it in a BigInt variable decimalValue
.void main() {
String binaryStr = '1010';
BigInt decimalValue = BigInt.parse(binaryStr, radix: 2);
print('Parsed binary to decimal: $decimalValue');
}
Parsed binary to decimal: 10
In this Dart tutorial, we learned about parse() static-method of BigInt: the syntax and few working examples with output and detailed explanation for each example.