summaryrefslogtreecommitdiff
path: root/src/Noddybox.Emulation.EightBit/Binary.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Noddybox.Emulation.EightBit/Binary.cs')
-rw-r--r--src/Noddybox.Emulation.EightBit/Binary.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/Noddybox.Emulation.EightBit/Binary.cs b/src/Noddybox.Emulation.EightBit/Binary.cs
new file mode 100644
index 0000000..0b1928b
--- /dev/null
+++ b/src/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
+{
+ /// <summary>
+ /// Provides helpers for shifting smaller values around without casts all over the shop.
+ /// </summary>
+ public static class Binary
+ {
+ /// <summary>
+ /// Shift 8-bits to the left.
+ /// </summary>
+ /// <param name="b">The byte.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static byte ShiftLeft(byte b, int shift)
+ {
+ return (byte)((b << shift) & 0xff);
+ }
+
+ /// <summary>
+ /// Shift 8-bits to the right.
+ /// </summary>
+ /// <param name="b">The byte.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static byte ShiftRight(byte b, int shift)
+ {
+ return (byte)((b >> shift) & 0xff);
+ }
+
+ /// <summary>
+ /// Shift 16-bits to the left.
+ /// </summary>
+ /// <param name="w">The word.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static ushort ShiftLeft(ushort w, int shift)
+ {
+ return (ushort)((w << shift) & 0xffff);
+ }
+
+ /// <summary>
+ /// Shift 16-bits to the right.
+ /// </summary>
+ /// <param name="w">The word.</param>
+ /// <param name="shift">How many bits to shift.</param>
+ /// <returns>The shifted value.</returns>
+ public static ushort ShiftRight(ushort w, int shift)
+ {
+ return (ushort)((w >> shift) & 0xffff);
+ }
+ }
+}