-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntExtensions.cs
39 lines (37 loc) · 962 Bytes
/
IntExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Text;
namespace WhitespaceAssembler
{
public static class IntExtensions
{
public static string ToWhitespace(this int value)
{
StringBuilder builder = new StringBuilder(65);
builder.Append('\n');
bool positive = value >= 0;
while (value > 0)
{
if (value % 2 == 0)
{
builder.Append(' ');
}
else
{
builder.Append('\t');
}
value /= 2;
}
if (positive)
{
builder.Append(' ');
}
else
{
builder.Append('\t');
}
char[] charArray = builder.ToString().ToCharArray();
Array.Reverse( charArray );
return new string( charArray );
}
}
}