7 kyu
Binary operations #1
198 of 923ItisAsimulation
Loading description...
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
RISCV Translation
python new test framework is required. updated in this fork
Approved
It is unclear what is the author mean by "flip" ! It is not only needed to switch 0 and 1, but also move the bit, but where to?
In the context of bitwise-operations flipping a bit is just that, setting it to 0 if it was 1 and to 1 if it was 0. Hint: note that indexes are 1-based in the kata.
Why is
index
in C++size_t
? Not that it matters too much, but it doesn't really make sense.COBOL translation (author inactive).
approved
C translation (author inactive)
Thanks :)
nice kata!
C++ tests can generate an index of 0. This is outside the defined range.
fixed
Ruby 3.0 should be enabled.
Fixed in this fork
C++ translation
approved by someone
Python 3 should be enabled.
This comment has been hidden.
forum is not dead!) on that line -> if (binValueList != null && bitIndex <= binValueList.Count) you check for bitIndex <= binValuelist.Count, but test cases can be like this : FlipBit(1,2) and bitIndex can be > than binValuelist.Count, so your result become empty and in that line -> int testBin = Convert.ToInt32(result.ToString(), 2); you have error.
This comment has been hidden.
else if (bitIndex > binValueList.Count) { result.Append(binValue.Insert(0, "1")); } in this line you add one bit in the beginning of result, But tests can be like this: FlipBit(127,17).In that case you should flip 17th bit of 8bit number, but in your code you flip 9th bit
Thanks for your tip. I dit not make it dynamic. Now this kata has been resolved. Not the best way but done. Still learning.
JavaScript, Ruby and Crystal translations kumited, cheers!
Better state explicitly that if bitIndex is bigger that length than it must be taken into account
Added an example with bitIndex bigger than length, along with the explanation of what to do in such a case.
Issue resolved.
I would change the description for the bit index a bit: Something like "the index of the least significant bit is 1".
Replaced young and senior with least significant and most significant.
Thanks. But I would also remove the "index 31 for MSB" for two reasons: For 32-bit integers, if you start with index 1 for 1st bit, the 32nd bit would be index 32, not 31. And for dynamically typed languages such as Python, the parameter depends on the type passed to the function - could also be a 64-bit long and therefore the MSB would be index 64. Not a real issue, but could be confusing, I think.
You are right. Removed the part about most significant bit.
Thank you! :-)
The name of the method in your starter code is flipBit, but it should be FlipBit.
I think it has been fixed now. Could you mark this issue as resolved?
OK, but instead of "Your work is to write method FlipBit(value , bitIndex)" you should write "Your work is to write method FlipBit(value , bitIndex) or flip_bit in Python."
Thanks for the feedback. Modified the description so it doesn't contain the name of the method. Language specific examples in description seemed better than mentioning method name for each language in the description.