-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a5e37b8
Showing
7 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/bin | ||
**/obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 :)"); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
BinaryToTCConverter/Properties/PublishProfiles/FolderProfile.pubxml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
10 changes: 10 additions & 0 deletions
10
BinaryToTCConverter/Properties/PublishProfiles/FolderProfile.pubxml.user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |