Skip to content

Commit

Permalink
1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
komunre committed Sep 23, 2022
0 parents commit a5e37b8
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/bin
**/obj
25 changes: 25 additions & 0 deletions BinaryToTCConverter.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BinaryToTCConverter", "BinaryToTCConverter\BinaryToTCConverter.csproj", "{61B6D1F1-84BA-4A3C-953E-B39C2F90F337}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{61B6D1F1-84BA-4A3C-953E-B39C2F90F337}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{61B6D1F1-84BA-4A3C-953E-B39C2F90F337}.Debug|Any CPU.Build.0 = Debug|Any CPU
{61B6D1F1-84BA-4A3C-953E-B39C2F90F337}.Release|Any CPU.ActiveCfg = Release|Any CPU
{61B6D1F1-84BA-4A3C-953E-B39C2F90F337}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {25F0563E-4A36-4E24-A6A1-F8E641893EBD}
EndGlobalSection
EndGlobal
10 changes: 10 additions & 0 deletions BinaryToTCConverter/BinaryToTCConverter.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions BinaryToTCConverter/BinaryToTCConverter.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_LastSelectedProfileId>D:\codes\BinaryToTCDecoder\BinaryToTCConverter\Properties\PublishProfiles\FolderProfile.pubxml</_LastSelectedProfileId>
</PropertyGroup>
</Project>
104 changes: 104 additions & 0 deletions BinaryToTCConverter/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// See https://aka.ms/new-console-template for more information
using System;
using System.Collections;
using System.Text;

namespace BinaryToTCDecoder
{
enum BitsQuant
{
BIT8 = 1,
BIT16 = 2,
BIT32 = 4,
BIT64 = 8,
}

class TCConverter
{
public static string Usage()
{
return "Program Usage: [input] [output] <bits 8|16|32|64 (optional)>";
}
public static void Main(String[] args)
{
// Thanks Tim Lloyd
void Reverse(BitArray array)
{
int length = array.Length;
int mid = (length / 2);

for (int i = 0; i < mid; i++)
{
bool bit = array[i];
array[i] = array[length - i - 1];
array[length - i - 1] = bit;
}
}

try
{
string input = args[0];
string output = args[1];
}
catch (IndexOutOfRangeException)
{
throw (new IndexOutOfRangeException("Not Enough Arguments. " + Usage()));
}

FileStream file = File.OpenRead(args[0]);
FileStream outFile = File.OpenWrite(args[1]);
outFile.SetLength(0);
outFile.Close();
outFile = File.OpenWrite(args[1]);

BitsQuant quant = BitsQuant.BIT8;

if (args.Length > 2)
{
int bits = int.Parse(args[2]);
switch (bits)
{
case 8:
break;
case 16:
quant = BitsQuant.BIT16;
break;
case 32:
quant = BitsQuant.BIT32;
break;
case 64:
quant = BitsQuant.BIT64;
break;
default:
throw (new InvalidDataException("NOT SUPPORTED QUANTITY OF BITS PER INSTRUCTION"));
}
}

Console.WriteLine("Starting conversion");

for (var i = 0; i < file.Length; i += (int)quant)
{
byte[] prepArr = new byte[(int)quant];
for (var j = 0; j < (int)quant; j++)
{
prepArr[j] = (byte)file.ReadByte();
}
var barr = new BitArray(prepArr);
Reverse(barr);
var bstr = "0b";
for (var j = 0; j < barr.Count; j++)
{
bstr += barr.Get(j) ? "1" : "0";
}
bstr += "\n";
Console.Write(bstr);
var bbstr = Encoding.ASCII.GetBytes(bstr);
outFile.Write(bbstr, 0, bbstr.Length);
}

outFile.Flush();

Console.WriteLine("Finished work. Enjoy :)");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>Any CPU</Platform>
<PublishDir>bin\Release\net6.0\publish\</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<History>True|2022-09-23T10:57:41.0169029Z;True|2022-09-23T17:53:35.9754742+07:00;True|2022-09-23T17:27:54.2376651+07:00;True|2022-09-23T17:15:54.9060264+07:00;False|2022-09-23T17:15:26.9625150+07:00;True|2022-09-21T20:00:25.2587723+07:00;True|2022-07-24T23:35:22.7373684+07:00;True|2022-07-24T23:30:58.8330197+07:00;True|2022-07-24T23:27:38.5926544+07:00;True|2022-07-24T23:27:12.8429232+07:00;True|2022-07-24T23:25:18.7522202+07:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>

0 comments on commit a5e37b8

Please sign in to comment.