Skip to content

Conversation

colinleach
Copy link
Contributor

I hope I understand this topic somewhat better than I understand Unicode (a low bar).

Comment on lines +21 to +22

Perhaps surprisingly, `Byte` or `Short` types are not compatible with most bitwise operations in Kotlin.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Perhaps surprisingly, `Byte` or `Short` types are not compatible with most bitwise operations in Kotlin.
Perhaps surprisingly, `Byte` or `Short` types are not compatible with most bitwise operations in Kotlin.

I didn't know this!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Since 1.5, UByte has or and xor and and and inv, same for UShort.
Byte has full support since 1.2, same for Short.

Copy link
Contributor Author

@colinleach colinleach Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's strange. The 2.2 docs say:

Bitwise operations are represented by functions that can be called in infix form. They can be applied only to Int and Long

I tried Byte and UByte in Kotlin Notebook, and couldn't get them to work with shl: "Unresolved reference. None of the following candidates is applicable because of receiver type mismatch".

I'm not getting much done today (reasons including all-day headache and brain fog), but I don't think I messed that up.

Copy link
Member

@SleeplessByte SleeplessByte Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yoooo my Short link actually linked to BigInteger which is also new to me.... we now need to update the numbers concept XD. BigDecimal also exists nvm, only JVM!

Anyway, yeah, it works for UShort and UByte. Not Short and Byte. And not all operations are supported for UShort and UByte! Only and, or, xor, and inv. Playground. This playground also compiles in JS and Wasm :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, producing a clear, concise Concept for a poorly documented mess could be ... challenging.

Still, we're all better informed now, I suppose.

Copy link
Contributor Author

@colinleach colinleach Sep 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: feel free to disagree, but I have some doubts about whether experimental and undocumented features belong in an Exercism syllabus. Though maybe I'm just old and unimaginative...

(I'm definitely old)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have some doubts about whether experimental and undocumented features

Experimental: maybe but I don't do that for the other tracks because it's a lot of work to keep track of.
Undocumented: sometimes, but in this case it's not undocumented. The Kotlin docs are out of date, the kotlin reference is not! That's how I found these: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-u-byte/#-1940364782%2FFunctions%2F-1430298843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants