Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,569 questions

56,787 answers

573 users

How to get the 4 least significant bits in a byte with Kotlin

1 Answer

0 votes
fun main() {
    val value: Byte = 0xD6.toByte()
    val lower4: Int = value.toInt() and 0x0F

    println("value  (dec): ${value.toInt() and 0xFF}")  // show as unsigned 214
    println("lower4 (dec): $lower4")

    val valueBin  = (value.toInt() and 0xFF).toString(2).padStart(8, '0')
    val lower4Bin = lower4.toString(2).padStart(4, '0')

    println("value  (bin):  $valueBin")
    println("lower4 (bin):  $lower4Bin")
}



/*
run:

value  (dec): 214
lower4 (dec): 6
value  (bin):  11010110
lower4 (bin):  0110

*/

 



answered Dec 28, 2025 by avibootz
...