From f96332b0913a8a365db73a1af3443c0e225a23d8 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 29 Dec 2011 00:17:13 +0000 Subject: Development check-in. --- Noddybox.Emulation.EightBit/Binary.cs | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Noddybox.Emulation.EightBit/Binary.cs (limited to 'Noddybox.Emulation.EightBit/Binary.cs') diff --git a/Noddybox.Emulation.EightBit/Binary.cs b/Noddybox.Emulation.EightBit/Binary.cs new file mode 100644 index 0000000..0b1928b --- /dev/null +++ b/Noddybox.Emulation.EightBit/Binary.cs @@ -0,0 +1,63 @@ +using System; +using System.Net; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Documents; +using System.Windows.Ink; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Animation; +using System.Windows.Shapes; + +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); + } + } +} -- cgit v1.3