2026-01-26 18:56:53 +09:00

43 lines
1.2 KiB
C#

using System;
namespace VisionLight {
// 8 bit 기준
public static class BitMaskUtil {
// 특정 비트 켜기 (Set ON)
public static byte SetBit(byte mask, int bitIndex) {
return (byte)(mask | (1 << bitIndex));
}
// 특정 비트 끄기 (Set OFF)
public static byte ClearBit(byte mask, int bitIndex) {
return (byte)(mask & ~(1 << bitIndex));
}
// 특정 비트 토글
public static byte ToggleBit(byte mask, int bitIndex) {
return (byte)(mask ^ (1 << bitIndex));
}
// 특정 비트가 켜져 있는지 확인
public static bool IsBitSet(byte mask, int bitIndex) {
return (mask & (1 << bitIndex)) != 0;
}
// 전체 비트 ON (8비트 기준)
public static byte AllOn() {
return 0xFF;
}
// 전체 비트 OFF
public static byte AllOff() {
return 0x00;
}
// 비트마스크를 이진 문자열로 보기 좋게 출력
public static string ToBinaryString(byte mask) {
return Convert.ToString(mask, 2).PadLeft(8, '0');
}
}
}