❔ How bit wise shift operation work
I started learning bit wise operation.
So i have a uint = 0101 bit which is int 5. Which is in loop to see how it works
Consider n =0101
1st iteration
var test = (n >> 0) // The value is 101
2nd iteration
var test = (n >> 1) // The value of test is 50
How this Happens what i assumed is 0101 on 2nd iteration will become as 1010 so it will be 9. But how it becomes 50.
5 Replies
n >> 0 doesn't do anything
also you seem to have confused a bit binary and decimal representations
you wrote 101 in decimal form
so when you shift it right by one bit, it becomes 50 (gets divided by two is the same as shifting one bit rightward)
Oryp4ik#0120
REPL Result: Success
Console Output
Compile: 558.327ms | Execution: 38.379ms | React with ❌ to remove this embed.
as you can see, it works
but I kept everything with binary base
Oryp4ik#0120
REPL Result: Success
Console Output
Compile: 542.355ms | Execution: 30.110ms | React with ❌ to remove this embed.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.