The `bitLength` property in Dart returns the minimum number of bits required to store this integer.
The syntax of int.bitLength property is:
int bitLength
This bitLength property of int returns the minimum number of bits required to store this integer.
int.bitLength returns value of type int
.
In this example,
number
with the value 15.bitLength
property to get the minimum number of bits required to store it.void main() {
int number = 15;
int bits = number.bitLength;
print('Bit length of $number: $bits');
}
Bit length of 15: 4
In this example,
largeNumber
with the value 1000000.bitLength
property to get the minimum number of bits required to store it.void main() {
int largeNumber = 1000000;
int bitsLarge = largeNumber.bitLength;
print('Bit length of $largeNumber: $bitsLarge');
}
Bit length of 1000000: 20
In this example,
negativeNumber
with the value -8.bitLength
property to get the minimum number of bits required to store it.void main() {
int negativeNumber = -8;
int bitsNegative = negativeNumber.bitLength;
print('Bit length of $negativeNumber: $bitsNegative');
}
Bit length of -8: 3
In this Dart tutorial, we learned about bitLength property of int: the syntax and few working examples with output and detailed explanation for each example.