BizHawk/BizHawk.Emulation.Cores/Computers/Commodore64/C64Util.cs

38 lines
769 B
C#
Raw Normal View History

2016-02-22 23:50:11 +00:00
using System.Text;
namespace BizHawk.Emulation.Cores.Computers.Commodore64
2014-12-18 18:39:55 +00:00
{
public static class C64Util
{
2016-02-22 23:50:11 +00:00
public static string ToBinary(int n, int charsmin)
2014-12-18 18:39:55 +00:00
{
2016-02-22 23:50:11 +00:00
var result = new StringBuilder(string.Empty);
2014-12-18 18:39:55 +00:00
while (n > 0 || charsmin > 0)
{
2016-02-22 23:50:11 +00:00
result.Insert(0, (n & 0x1) != 0 ? "1" : "0");
2014-12-18 18:39:55 +00:00
n >>= 1;
if (charsmin > 0)
charsmin--;
}
2016-02-22 23:50:11 +00:00
return result.ToString();
2014-12-18 18:39:55 +00:00
}
2016-02-22 23:50:11 +00:00
public static string ToHex(int n, int charsmin)
2014-12-18 18:39:55 +00:00
{
2016-02-22 23:50:11 +00:00
var result = new StringBuilder(string.Empty);
2014-12-18 18:39:55 +00:00
2016-02-22 23:50:11 +00:00
while (n > 0 || charsmin > 0)
2014-12-18 18:39:55 +00:00
{
2016-02-22 23:50:11 +00:00
result.Insert(0, "0123456789ABCDEF".Substring(n & 0xF, 1));
2014-12-18 18:39:55 +00:00
n >>= 4;
if (charsmin > 0)
charsmin--;
}
2016-02-22 23:50:11 +00:00
return result.ToString();
2014-12-18 18:39:55 +00:00
}
}
}