Bird
0
0

You want to represent the decimal number 255 in Kotlin using a binary literal with underscores for readability. Which of the following is the best way to write it?

hard📝 Application Q15 of 15
Kotlin - Data Types
You want to represent the decimal number 255 in Kotlin using a binary literal with underscores for readability. Which of the following is the best way to write it?
A<code>0b1111_1111</code>
B<code>0b11111111</code>
C<code>0b1111_1110</code>
D<code>0b1111_11112</code>
Step-by-Step Solution
Solution:
  1. Step 1: Convert decimal 255 to binary

    255 in binary is 11111111 (eight ones).
  2. Step 2: Add underscores for readability

    Grouping bits in fours is common, so 1111_1111 is clearer and valid.
  3. Step 3: Check options for correctness

    0b1111_1111 correctly uses underscores and matches 255. 0b11111111 is correct but less readable. 0b1111_1110 is 254, and 0b1111_11112 has invalid digit '2'.
  4. Final Answer:

    0b1111_1111 -> Option A
  5. Quick Check:

    Binary 1111_1111 = 255 decimal [OK]
Quick Trick: Group binary digits in fours with underscores [OK]
Common Mistakes:
MISTAKES
  • Using wrong binary digits
  • Adding invalid digits like 2
  • Not grouping bits for readability

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes