Home > Software design >  Binary alienation algorithm, blocks of 64
Binary alienation algorithm, blocks of 64

Time:03-11

I have an alienation pattern that I want to implement, the problem is that I'm not good at math, and I don't know how to do it and how to start.

Here's the explanation:

  0 to 31  result: 0
 32 to 95  result: 36
 96 to 159 result: 72
160 to 223 result: 108
224 to 287 result: 144
288 to 351 result: 180
352 to 415 result: 216
etc...

If the input number is less than 32, always returns zero. But if the input number is between 32 and 95 (32 and 95 included) returns 36, and so on for all blocks. I think that works with blocks of 63, and the result increases in 36.

How should I program it to get these results?? Not sure if there is a formula to calculate this, because the minimum input would be 0, but the max input could be 4294967295.

Here's the code that I currently have:

public static uint GetXboxAlignedNumber(uint inputValue)
{
    uint alignedValue = 0;
    if (inputValue < 32)
    {
        alignedValue = 0;
    }
    else
    {
        //Here goes the code
    }

    return alignedValue;
}

Thanks!!

CodePudding user response:

This should work

if (inputValue < 32)
{
    return 0;
}
else
{
    return (Math.Floor((inputValue - 32) / 64)   1) * 36;
}
  • Related