// This file is part of the Noddybox.Emulation C# suite. // // Noddybox.Emulation is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Noddybox.Emulation is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Noddybox.Emulation. If not, see . // // Copyright (c) Ian Cowburn 2012 // using System; namespace Noddybox.Emulation.EightBit { /// /// Provides helpers for shifting smaller values around without casts all over the shop. /// public static class Binary { /// /// Shift 8-bits to the left. /// /// The byte. /// How many bits to shift. /// The shifted value. public static byte ShiftLeft(byte b, int shift) { return (byte)((b << shift) & 0xff); } /// /// Shift 8-bits to the right. /// /// The byte. /// How many bits to shift. /// The shifted value. public static byte ShiftRight(byte b, int shift) { return (byte)((b >> shift) & 0xff); } /// /// Shift 16-bits to the left. /// /// The word. /// How many bits to shift. /// The shifted value. public static ushort ShiftLeft(ushort w, int shift) { return (ushort)((w << shift) & 0xffff); } /// /// Shift 16-bits to the right. /// /// The word. /// How many bits to shift. /// The shifted value. public static ushort ShiftRight(ushort w, int shift) { return (ushort)((w >> shift) & 0xffff); } } }