3 ms·
Ask and you shall receive, here is the output it gave me: // Write a Go function to swap the sixth bit and seventeenth bit of a 32-bit signed integer.
by c4wrd 5y ago
Ask and you shall receive, here is the output it gave me:
// Write a Go function to swap the sixth bit and seventeenth bit of a 32-bit signed integer.
package main
import (
"fmt"
"math"
)
func main() {
var a int32 = 0b1010101010101010101010101010101010101010101010101010101010101010
fmt.Printf("%b\n", a)
fmt.Printf("%b\n", swapBits(a, 6, 17))
}
func swapBits(a int32, i int, j int) int32 {
// convert to binary
bin := fmt.Sprintf("%b", a)
// get the bits
bit1 := bin[i-1 : i]
bit2 := bin[j-1 : j]
// swap the bits
bin = bin[:i-1] + bit2 + bin[i:]
bin = bin[:j-1] + bit1 + bin[j:]
// convert back to int
return int32(bin2int(bin))
}
func bin2int(bin string) int64 {
var sum int64
for i, v := range bin {
if v == '1' {
sum += int64(math.Pow(2, float64(len(bin)-i-1)))
}
}
return sum
}
- 37ef_ced3 5y agoRidiculous. It's a joke, right? Perhaps the most inefficient and naive solution ever? CoPilot is regurgitating some solution from its training set, the solution of an inept programmer who would manipulate bits via conversion to string... yikes.
- skulk 5y agoThe next iteration of code assistant needs to be able to parse responses like your comment and update the code accordingly. Once a human+computer pair can converge on a correct and admissible solution to _any_ tractable programming task through natural language dialogue, we should start worrying about our jobs going away. Until then, for each line of code generated by AI, there will be two jobs created to maintain that code.
- hackinthebochs 5y agoWhich direction in feature space do you move in response to "you inept POS"?
- electroly 5y agoCopilot can do that, sorta. You undo the completion and add something like "... but don't convert it to a string" to the comment, then have it try completing again.