FYI: The most replies on a topic was an updates post made by Josh, having around 4,700 replies (?) before it got deleted.
This does not. If you were to scroll up and read them, you’ll find that almost all of them are on topic discussing math and bitwise. High reply counts are not inherently bad.
about 900-1000+ replies
bump because unresolved maths
*semi unresolved maths
The entire post is irrelevant due to the text operations update, and really just exists as a fun math problem to solve. Getrithekd actually found a semi-solution that worked in just the cases I needed it for, but it doesn’t work for everything, so the problem remains open.
yeah i should probably read all 750 replies before saying something
hi I just sent this in discord
just divide by 2^n(right shift n) and check if result is 1 mod 2
assuming integer/integer gives integer rounded down
I need to afk go to class, msg me on discord
Alright, for those not on discord, eesoog provided a similar solution to getrithekd’s. His other idea which is interesting is that you could precompute tables of answers for the bitwise AND of different numbers, which, although it involves loops still, would be interesting to think about.
That’s pretty much what this is now haha.
I’m actually trying to prove a non-looping solution impossible now.
Good luck!
im laughing my apple off rn
classic post by blackhole
I got this from ChatGPT:
def bitwise_and_with_power_of_2(number, n):
# Check if the bit at the n-th position of 2^n exists in the number
if (number >> n) & 1:
return 2**n
else:
return 0
# Example usage
number = 2863311530
n = 0
result = bitwise_and_with_power_of_2(number, n)
print(result) # Output will be 1
Btw the code is python. idk how to translate it to Gimkit coding.
oh yeah, carrot is also why I am here
Let’s break down how the bitwise_and_with_power_of_2
function works:
- Function Purpose: This function checks whether a specific bit (corresponding to 2𝑛2n) is set (i.e., equals 1) in the binary representation of a given number.
- Function Logic:
number >> n
: This shifts the binary representation ofnumber
to the right byn
positions. This effectively isolates the bit at then
-th position.& 1
: This performs a bitwise AND operation with1
, which checks whether the isolated bit is1
(if the result is non-zero) or0
(if the result is zero).
- Return Value:
- If the
n
-th bit ofnumber
is1
, the function returns 2𝑛2n. - If the
n
-th bit ofnumber
is0
, the function returns0
.
- Example Usage: Let’s analyze the example provided:
python
Copy code
number = 2863311530 # Binary: 10101010101010101010101010101010
n = 0
result = bitwise_and_with_power_of_2(number, n)
print(result) # Output will be 1
number
in binary:10101010101010101010101010101010
- Bit at position
n=0
:0
(number >> n) & 1
evaluates to(2863311530 >> 0) & 1
, which simplifies to2863311530 & 1
.2863311530 & 1
equals0
.- Therefore, the function returns
0
because the bit at positionn=0
ofnumber
is0
.
- Summary:
- The function
bitwise_and_with_power_of_2
is designed to check if a specific bit in the binary representation of a number is set and returns the corresponding power of2
if true, or0
if false.
In the provided example, since the bit at position n=0
of number
is 0
, the output of result
is 0
. If you change n
to 1
, 2
, etc., you can check different bit positions accordingly. is what chat gpt said
imo while loops are better, but for loops are insanely useful too. (also I’m back yay )
Oh yeah I forgot to mention that I needed this for my 3D renderer lol, I don’t think I ever said that.
I’m-back-bump!