Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit dffba0e

Browse files
committed
Added numbers and fixed file output.
1 parent f473676 commit dffba0e

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

LiberPrimusAnalysisTool.Application/Commands/Math/CircularShift.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,36 @@ public async Task<string> Handle(Command request, CancellationToken cancellation
114114
case "ASCII":
115115
result.AppendLine(ConvertBinaryToAscii(binaryStrings));
116116
break;
117+
case "NUMBERS":
118+
List<long> numbers = new();
119+
foreach (var binaryString in binaryStrings)
120+
{
121+
var value = Convert.ToInt64(binaryString, 2);
122+
numbers.Add(value);
123+
}
124+
result.AppendLine(string.Join(", ", numbers));
125+
break;
117126
default:
118127
List<byte> bytes = new();
119128
foreach (var binaryString in binaryStrings)
120129
{
121-
if (binaryString.Length % 8 != 0)
130+
StringBuilder binaryStringBuilder = new();
131+
for (int i = 0; i < binaryString.Length; i++)
122132
{
123-
bytes.Add(Convert.ToByte(binaryString));
124-
}
125-
else
126-
{
127-
StringBuilder binaryStringBuilder = new();
128-
for (int i = 0; i < binaryString.Length; i++)
133+
binaryStringBuilder.Append(binaryString[i]);
134+
if (binaryStringBuilder.Length == 8)
129135
{
130-
binaryStringBuilder.Append(binaryString[i]);
131-
if (binaryStringBuilder.Length % 8 == 0)
136+
var value = Convert.ToInt64(binaryString, 2);
137+
if (value is > byte.MaxValue or < byte.MinValue)
132138
{
133-
bytes.Add(Convert.ToByte(binaryStringBuilder.ToString()));
134-
binaryStringBuilder.Clear();
139+
throw new Exception("Value is greater or less than byte max value");
135140
}
141+
bytes.Add(Convert.ToByte(value));
142+
binaryStringBuilder.Clear();
136143
}
137-
138-
await File.WriteAllBytesAsync(request.OutputType, bytes.ToArray(), cancellationToken);
139144
}
145+
146+
await File.WriteAllBytesAsync(request.OutputType, bytes.ToArray(), cancellationToken);
140147
}
141148

142149
result.AppendLine($"Please check the output file: {request.OutputType}");

LiberPrimusUi/ViewModels/CircularShiftViewModel.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public CircularShiftViewModel(IMediator mediator)
2727
OutputList.Add("File");
2828
OutputList.Add("ANSI");
2929
OutputList.Add("ASCII");
30+
OutputList.Add("NUMBERS");
3031

3132
for(int i = 1; i <= 64; i++)
3233
{
@@ -71,6 +72,9 @@ public async void Process()
7172
case "ASCII":
7273
output = "ASCII";
7374
break;
75+
case "NUMBERS":
76+
output = "NUMBERS";
77+
break;
7478
}
7579

7680
var command = new CircularShift.Command(

0 commit comments

Comments
 (0)