Recall & Review
beginner
What is the purpose of using underscores in Kotlin number literals?
Underscores in Kotlin number literals make large numbers easier to read by visually separating digits, like commas in regular numbers. They do not affect the actual value.
Click to reveal answer
beginner
How do you write a hexadecimal number literal in Kotlin?
In Kotlin, a hexadecimal number literal starts with
0x or 0X followed by digits 0-9 and letters A-F (case insensitive). For example, 0x1A3F.Click to reveal answer
beginner
How do you write a binary number literal in Kotlin?
A binary number literal in Kotlin starts with
0b or 0B followed by only 0s and 1s. For example, 0b1010_1101.Click to reveal answer
intermediate
Can underscores be placed anywhere in Kotlin number literals?
Underscores can be placed between digits in Kotlin number literals to improve readability, but not at the start or end of the number, nor next to the decimal point or prefixes like
0x or 0b.Click to reveal answer
intermediate
Example: What is the decimal value of
0xFF_EC_DE_5E in Kotlin?The hexadecimal literal
0xFF_EC_DE_5E equals 4293713502 in decimal. The underscores are ignored when computing the value.Click to reveal answer
Which of the following is a valid Kotlin binary literal?
✗ Incorrect
Binary literals start with 0b or 0B and contain only 0s and 1s. Option D is correct.
What does the underscore do in Kotlin number literals?
✗ Incorrect
Underscores improve readability but do not affect the number's value.
Which prefix is used for hexadecimal literals in Kotlin?
✗ Incorrect
Hexadecimal literals start with 0x or 0X.
Is this Kotlin number literal valid?
0x_1A3F✗ Incorrect
Underscores cannot be placed immediately after the prefix like 0x.
What is the decimal value of
0b1111_0000?✗ Incorrect
Binary 11110000 equals decimal 240.
Explain how to write and use underscores in Kotlin number literals.
Think about how commas help read big numbers.
You got /4 concepts.
Describe how to write hexadecimal and binary number literals in Kotlin with examples.
Remember the prefixes and allowed digits.
You got /4 concepts.