Created functions to allow for data to be written to and read from memory using bianry strings.

This commit is contained in:
2026-05-31 20:36:00 -04:00
parent 9efadc3b4a
commit a958d11c4e
13 changed files with 83 additions and 15 deletions
+21
View File
@@ -9,6 +9,14 @@ namespace CPUSimulation
{
_value = value;
}
public Bit(string bitString)
{
if (bitString.Length != 1 || (bitString != "0" && bitString != "1"))
{
throw new ArgumentException("Bit string must be '0' or '1'.");
}
_value = bitString == "1";
}
public bool GetValue()
{
return _value;
@@ -26,6 +34,19 @@ namespace CPUSimulation
_bits = bits;
}
public Byte(string bitString)
{
if (bitString.Length != 8)
{
throw new ArgumentException("Bit string must be exactly 8 characters long.");
}
_bits = new Bit[8];
for (int i = 0; i < 8; i++)
{
_bits[i] = new Bit(bitString[i] == '1');
}
}
public Bit[] GetBits()
{
return _bits;