Bitwise operations in gimkit

This is true. Fun fact VEX Robotics V5 block code is just Scratch but for Vex V5. If you don’t understand what this means, that is fine, I guess.

1 Like

bump cuz ye.

I’m going to try and revive bitwise operations in my wiki.

There needs to be a way without using sums.

by 2^n, what do you mean? is “n” any positive integer?
2863311530 is 10101010101010101010101010101010 in base 2

1 Like

also, what is the goal of the problem?
to find the result of the bitwise AND operation?

1 Like

Yeah, he said it needs to be able to solve due any value of n.

1 Like

IDK I’m in the wrong department fella! I work to help with gimkit!

1 Like

Ok
lets split this into 3 cases:

Case 1: n is odd and less than 32
Notice that in 10101010101010101010101010101010, each 1 is in the evens digit. In other words, it could be written as 2^31 + 2^29 +2^27 … + 2^1 (Note that the first digit of base 2 is written as 0 x 2^0, so each digit after that increases its power by one). Since n is odd and less than 33, it’s base 2 representation is 1000…000 with n zero’s. The one at the front also coincides with one of the original number’s digits. Since the Bitwise AND operation multiplies corresponding digits, everything will cancel out (due to the zero’s) except for the corresponding 1’s, which stay as a 1. The result is 2^n

Case 2: n is even and less than 32
Remember that 10101010101010101010101010101010 can be written as 2^31 +2^29 +… + 2^1
Since n is even, the resulting leading 1 won’t coincide with any of the 1’s.
Thus, everything cancels out and the result is 0.

Case 3: n is greater or equal to 32
In this case:
n>32
2^n > 2^32
2^n > 2^31 + 2^31
2^n > 2^31 + 2^30 + 2^30
2^n > 2^31 + 2^30 + 2^ 29 + 2^29
and so on, until
2^n > 2^31 + 2^30 + 2^29 … + 2^3 + 2^2 + 2^1 + 2^0 + 2^0
We can remove the second 2^0
2^n > 2^31 + 2^30 + 2^29 … + 2^3 + 2^2 + 2^1 + 2^0
Now, notice that
2^31 + 2^30 + 2^29 … + 2^3 + 2^2 + 2^1 + 2^0 > 2^31 + 2^29 +2^27 … + 2^1
Since this expression is greater than the number, and 2^n is greater than the expression, we have
2^n > 2^31 + 2^29 +2^27 … + 2^1
What does this mean?
Well, this means that the leading digit 1 in 2^n will not coincide with any of the number’s digits. Since there are no coinciding 1’s, the result is 0.

Coding this in gimkit:
if {n>32}
do [set property: result
[value : 0
else if {n is odd}
do [set property: result
[value : {2^n}
else if {n is even}
do [set property: result
[value : 0

We don’t need to add {n<32} for the 2nd and 3rd conditionals because we already have it in the first.

DICLAIMER: This does not include negative numbers, so in the next post I’ll be covering those.

6 Likes

obviously, a six yr old doesn’t even know algebra

1 Like

Case 4: n is negative
This brings us to the world of decimals in different bases
For time’s sake, I’ll assume readers know about decimal representations in different bases
If n is negative, the result will be something like this 0.00…0001
Assuming Bitwise AND operations work on decimals, the result will be 0, as no 1’s coincide with each other.

Case 5: n is zero
2^0 = 1
No 1’s coincide. the result is 0

4 Likes

Updated Block Code:
(coming soon)

1 Like

Updated block code:
if {n>32}
do [set property: result
[value: 0
else if {n is negative}
do [set property: result
[value: 0
else if {n is 0}
do [set property: result
[value: 0
else if {n is even}
do [set property: result
[value: 0
else
do [set property: result
[value: {2^n}

1 Like

I’ll show this to black hole and see what he says. What math are you in?

1 Like

isn’t that sharing personal info

im in alg 1

1 Like

in school, im in geometry
in technical terms, i honestly dont know
im taking the AIME in february this year

hey @ClicClac ! Do you want to build a s̶n̶o̶w̶m̶a̶n milk-based base on @Blizzy 's mountain?

4 Likes

Really??? Wow… I’m only taking AMC 8…
I’m in alg1…

@Pika_Pokemon You shouldn’t tell me if you wanted to build a base…

1 Like

kool
amc 10 is better tho

ummm uhhh. i thought my relay only sent notified @ClicClac . oh wait a sec. I dont have a relay!

3 Likes

We should probably take this conversation to the pad let, drop-downs don’t do anything to hide off topic posts.

3 Likes

what padlet?

1 Like