using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bitwise
{
public static class BitwiseStuff
{
public static void TurnBitOn(int position, ref int data)
{
if (position > 
throw new Exception("Position cannot be greater than 8");
data |= (1 << position);
}
public static void TurnBitOff(int position, ref int data)
{
if (position > 
throw new Exception("Position cannot be greater than 8");
data &= ~(1 << position);
}
public static void SwapInts(ref int a, ref int b) //no temp BS
{
a ^= b;
b ^= a;
a ^= b;
}
public static void QuickSwapSign(ref int a)
{
a = ~a + 1;
}
public static bool QuickIsEven(int a)
{
return (a & 1) == 0;
}
public static bool QuickIsOdd(int a)
{
return !QuickIsEven(a);
}
public static void QuickModuloDivide(ref int a, int mod)
{
int temp = (mod - 1);
a &= temp;
}
public static int QuickAbsoluteValue(int a)
{
return (a < 0) ? -a : a;
}
public static int QuickFloor(double x)
{
return (int)x | 0;
}
public static int QuickFloor(float x)
{
return (int)x | 0;
}
public static int QuickCeiling(float x)
{
return QuickFloor(x + 1);
}
public static int QuickCeiling(double x)
{
return QuickFloor(x + 1);
}
public static double QuickRound(float d)
{
return (d - (int)d) < .5 ?
(int)d | 0 :
(int)(d + 1) | 0 ;
}
public static double QuickRound(double d)
{
return (d - (int)d) < .5 ?
(int)d | 0 :
(int)(d + 1) | 0 ;
}
}
}
Copyright © 2026, NextGenUpdate.
All Rights Reserved.