0
数値の各ビットに係数を乗算する方法が必要です。たとえば、factorが3の場合、番号の次のビットが使用される前に、その番号の各ビットが3回使用されます。 私はGLSLを使っています。因子(GLSL)でビットを掛ける
数値の各ビットに係数を乗算する方法が必要です。たとえば、factorが3の場合、番号の次のビットが使用される前に、その番号の各ビットが3回使用されます。 私はGLSLを使っています。因子(GLSL)でビットを掛ける
はC#
private int DuplicateBitsByFactor(int value, int factor)
{
var size = sizeof(ushort) * 8;
var binaryString = new StringBuilder();
for (var i = size; i >= 0; i--)
for (var j = 0; j < factor; j++)
binaryString.Append(GetBitOnLocation(value, i));
var duplicateBitsByFactor = Convert.ToInt32(binaryString.ToString(), 2);
return duplicateBitsByFactor;
}
private int GetBitOnLocation(int value, int location)
{
return (value & (1 << location)) == 0 ? 0 : 1;
}
で任意の最適化をやりましたか?