Created functions to allow for data to be written to and read from memory using bianry strings.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user