-1

I am trying to understand if there is any way I could have worded my inputs better to get an exact answer from ChatGPT. I am using the free web version by open ai (https://chat.openai.com/)

I was trying to find out how to do bitwise shifts in Kotlin. Along with my question, I gave it a rough expression, how I would have done it in Java (using << operator), and included the exact error message shown in Android studio as part of my question. In its answer, it explained the reasoning behind the error message and did not outright say << and >> are wrong, but included the correct way to do bitwise shift operations (shl and shr) and also provided sample code.

My next question to it was

does kotlin have >> and << operators for bitwise shifts?

To which it answered (in part)

Yes, Kotlin does have >> (signed right shift) and << (left shift) operators for bitwise shifts, similar to many other programming languages.

The << operator performs a bitwise left shift, shifting the bits of a binary number to the left by a specified number of positions. For example, x shl 2 will shift the bits of x two positions to the left.

The >> operator performs a signed bitwise right shift, shifting the bits of a binary number to the right by a specified number of positions, while preserving the sign (sign extension). For example, x shr 2 will shift the bits of x two positions to the right while preserving the sign of the original value.

Followed by sample code and sample output.

Then I ask

--

so does it recognise >> and << a valid tokens or not?
to which the reply was

--

Apologies for the confusion in my previous response. I made an error in my explanation. To clarify:

In Kotlin, the >> and << operators are valid and recognized tokens for bitwise shifts, just like in many other programming languages. So, you can use >> for signed right shift and << for left shift in Kotlin.

Here's the corrected example of using the >> and << operators in Kotlin:

--

Followed by the same sample code as above and sample output. At the end of this reply, it says this:

In this example, x shl 2 shifts the bits of x two positions to the left, resulting in 40, and x shr 2 shifts the bits two positions to the right, resulting in 2.

To summarize, yes, Kotlin recognizes >> and << as valid tokens for bitwise shifts. You can use them for performing bitwise left and signed right shifts, respectively.

which, according to this, is just wrong

Despite the fact that the usual symbols, like <<, >>, |, &, and ^, are missing, we can do everything we can in C, but with functions of classes Int and Long.

Other than this, I have found it answered most questions about Kotlin pretty correct. It also seems to know >> and << cannot be used in Kotlin, as the sample code generated never uses them, and yet, in the description, it flat out says >> and << exist.

If I didn't already know << and >> are not valid shift operators in Kotlin, this might have been very confusing. Is there any way I could have prompted the question to make it clearly say >> and << are not allowed? It seems to know this, at least, since it didn't use them in the sample code. Is using the characters >> and << as part of the input text a problem?

If it's relevant, before asking this question, there already was a long conversation all about Kotlin, but not about this specific topic.

2
  • Could this be the first question that ask for the "ready-to-go" prompt?
    – holydragon
    Aug 3, 2023 at 10:43
  • First, Kotlin is a vendor-dependent language and far less common than Java, Python, JavaScript, etc., which means that ChatGPT has been trained with much less data than more common languages. Second, LLMs are bad at telling what doesn't exist than what does. This is again due to the lack of training data saying that the operators >>, ***, <=>, etc. do not exist in Kotlin, and the fact that LLMs can interpolate but not extrapolate (from the facts that >> exists in Java and Kotlin is similarly to Java, the false assertion can be interpolated that in Kotlin >> is a shift operator).
    – howlger
    Aug 3, 2023 at 11:46

1 Answer 1

0

Please note that ChatGPT may not always provide reliable facts as it is based on the sources used to train it. While it occasionally provides accurate information, it may also respond creatively when it does not have sufficient data. Per its training, it might sound confident that it "knows" what it's talking about, but it hasn't an awareness of what is a fact and correct and what is not supported by facts or what might be wrong.

It is important to remember that ChatGPT is designed for conversations, so you do not need to provide all the information in one prompt. Additionally, ChatGPT can be extended through plug-ins. However, it is important to consider whether a plug-in is available for the specific topic you are interested in.

For example, if you don't have access to a plug-in that extends ChatGPT to provide reliable responses about Kotlin, you may need to prepare to teach ChatGPT about it before getting accurate responses. In any case, it is also recommended to be prepared to validate the information provided by ChatGPT.

I advise you not to use ChatGPT in scenarios where factual responses are critical. For example, if you haven't the skills and time to validate the responses in a professional software development setting.

Addendum

Stuff found on the web about ChatGPT and Kotlin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.