-
-
Notifications
You must be signed in to change notification settings - Fork 202
Add Bitwise Operations concept #716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
||
Perhaps surprisingly, `Byte` or `Short` types are not compatible with most bitwise operations in Kotlin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
Co-authored-by: Derk-Jan Karrenbeld <[email protected]>
Co-authored-by: Derk-Jan Karrenbeld <[email protected]>
Co-authored-by: Derk-Jan Karrenbeld <[email protected]>
I hope I understand this topic somewhat better than I understand Unicode (a low bar).