forked from alt-romes/programmer-calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
245 lines (191 loc) · 10.1 KB
/
index.html
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
<!DOCTYPE html>
<html>
<style type="text/css">
section {
margin: 0 auto;
max-width: 50em;
line-height: 1.5;
padding: 4em 1em;
color: #555; /*Subtle body text color*/
font-family: "Andale Mono", monospace;
}
h2 {
margin-top: 1em;
padding-top: 1em;
}
h1, h2, strong {
color: #333;
}
a {
color: #38A700; /*Primary color*/
}
img {
max-width: 100%;
height: auto;
border-radius: 15px;
box-shadow: rgba(0, 0, 0, 0.56) 0px 22px 70px 4px;
}
.imgc {
padding: 3em;
text-align: center;
}
pre {
padding: 1em;
border-radius: 6px;
background-color: rgb(246, 248, 250);
color: #333;
}
.comment {
color: #777;
}
.inline-code {
color: #333;
background-color: rgb(246, 248, 250);
}
</style>
<head>
<title>Programmer Calculator</title>
</head>
<body>
<section>
<h2>Programmer calculator</h2>
<p> The programmer calculator <a href="https://github.com/alt-romes/programmer-calculator">(github)</a> is a simple terminal tool designed to give maximum efficiency and flexibility to the programmer working with: </p>
<ul>
<li>binary, hexadecimal and decimal representations at the same time</li>
<li>bitwise operations</li>
<li>various operand sizes <small class="comment">(16bits, 32bits, 8bits, etc)</small></li>
</ul>
<p> and who likes: </p>
<ul>
<li>a clear, simple and customizable interface</li>
<li><a href="https://github.com/alt-romes/programmer-calculator">open source</a> software</li>
<li>terminal/cli tools</li>
</ul>
<div class="imgc">
<img style="width: 75%;" src="assets/final.png" alt="calculator">
</div>
<h2>Making of</h2>
<p> The idea was born while developing a Nintendo Gameboy Emulator. Romes - the pitcher - found that the tools given online were clunky and did not allow for "nice multitasking" </p>
<p> With the constant need to visualize and manipulate bits, it became evident that a better solution had to come to life </p>
<p> <em>"God wills, man thinks, the work is born."</em> - Fernando Pessoa, "A Mensagem"</p>
<h2>Installation</h2>
<h4>Homebrew</h4>
<p>First, create a new tap</p>
<pre><code>$ brew tap alt-romes/pcalc</code></pre>
<p>Then, install the program</p>
<pre><code>$ brew install pcalc</code></pre>
<h4>Arch Based Linux</h4>
<p>Install from AUR</p>
<pre><code>$ yay -S programmer-calculator</code></pre>
<h4>Building from Source <small>(alternative)</small></h4>
<p>To build from source you need <span class="inline-code">gcc</span>, <span class="inline-code">ncurses</span>, and the source files. <br><small style="color: #FF570A">If you don't have ncurses, please install it (i.e. with your system's package manager) first.</small></p>
<p>First, clone the repository</p>
<pre><code>$ git clone https://github.com/alt-romes/programmer-calculator</code></pre>
<p>Then, compile the code into an executable file</p>
<pre><code>$ make</code></pre>
<small>Alternatively, if you don't have make installed, compile with</small>
<pre><code>$ gcc main.c -o pcalc -lncurses</code></pre>
<p>Finally, move the executable to a directory reachable by $PATH</p>
<pre><code>$ mv -i pcalc /usr/local/bin</code></pre>
<h4>Updating</h4>
<p>Either re-build from source, or, using brew do</p>
<pre><code>$ brew update</code></pre>
<p>folowed by</p>
<pre><code>$ brew upgrade pcalc</code></pre>
<h4>Running</h4>
<p>Just run the programmer calculator program</p>
<pre><code>$ pcalc</code></pre>
<h2>Features</h2>
<h4>Usage</h4>
<p>There are various ways to insert values/operators, see the example <span class="inline-code">2 + 2</span> below:</p>
<ul>
<li><span class="inline-code">2</span>, followed by <span class="inline-code">+</span>, followed by <span class="inline-code">2</span></li>
<li><span class="inline-code">2</span>, followed by <span class="inline-code">+2</span></li>
<li><span class="inline-code">2+</span>, followed by <span class="inline-code">2</span></li>
<li><span class="inline-code">2+2</span> <small class="comment">(or <span class="inline-code">2 + 2</span>, <span class="inline-code">2 +2</span>, <span class="inline-code">2+ 2</span>, ...)</small></li>
</ul>
<p>You can also do inline math, but without priorities.</p>
<p>This means <span class="inline-code">2 + 3 * 2</span> is valid, but it's equal to <strong>10</strong>, not <strong>8</strong>, because expressions are evaluated from left to right</p>
<p>That said, any inline math is valid i.e.: <span class="inline-code">0x13 + 135 - 0b101 < 2 * 3 ~</span></p>
<br>
<h4>Hex + Binary + Decimal</h4>
<p>All three number representations are available at the same time, you can insert <span class="inline-code">0xff + 0b101101 - 5</span> directly onto the calculator</p>
<br>
<h4>Operand Size</h4>
<p>By default, 64 bits are used for arithmetic, however, when working with bits, quite often we want to work with less. With this calculator you can change the amount of bits used. <small class="comment">the number displayed will be unsigned</small></p>
<p>To use 16 bits instead, type <span class="inline-code">16cb</span> <small class="comment">(cb for "change bits")</small></p>
<p>To use 8 bits, type <span class="inline-code">8cb</span></p>
<p>To use 0 < <em>n </em><= 64 bits, type <span class="inline-code"><em>n</em>cb</span></p>
<br>
<h4>Customizing Interface</h4>
<p>While running the calculator, you can type <em>what you see</em> for it to appear/disappear:</p>
<ul>
<li><span class="inline-code">history</span> to toggle the history</li>
<li><span class="inline-code">decimal</span> to toggle the decimal representation</li>
<li><span class="inline-code">binary</span> to toggle the binary representation</li>
<li><span class="inline-code">hex</span> to toggle the hexadecimal representation</li>
<li><span class="inline-code">operation</span> to toggle the operation display</li>
</ul>
<p>To set a default interface, define an alias for the program with the desired hidden options</p>
<pre>$ alias pcalc='pcalc -hbxdos'</pre>
<small class="comment">h: history, b: binary, x: hex, d: decimal, o: operation, s: symbols</small><br>
<br>
<h4>Operations</h4>
<pre>ADD + SUB - MUL * DIV / MOD %
AND & OR | NOR $ XOR ^ NOT ~
SL < SR > RL ( RR ) 2's '</pre>
<ul>
<li>ADD: a + b <small class="comment">arithmetic addition</small></li>
</ul>
<ul>
<li>SUB: a - b <small class="comment">arithmetic subtraction</small></li>
</ul>
<ul>
<li>MUL: a * b <small class="comment">arithmetic multiplication</small></li>
</ul>
<ul>
<li>DIV: a / b <small class="comment">arithmetic integer division</small></li>
</ul>
<ul>
<li>MOD: a % b <small class="comment">modulus from the division</small></li>
</ul>
<ul>
<li>AND: a & b <small class="comment">bit-wise AND (&) operation </small></li>
</ul>
<ul>
<li>OR : a | b <small class="comment">bit-wise OR (|) operation </small></li>
</ul>
<ul>
<li>NOR: a $ b <small class="comment">bit-wise NOR ($) operation : opposite of OR</small></li>
</ul>
<ul>
<li>XOR: a ^ b <small class="comment">bit-wise XOR (^) operation : exclusive OR</small></li>
</ul>
<ul>
<li>NOT: a~ <small class="comment">bit-wise NOT (~) operation : change all bits of <em>a</em>, 0's into 1's and 1's into 0's</small></li>
</ul>
<ul>
<li>SL : a < b <small class="comment">bit-wise SHIFT-LEFT (<) operation : shift <em>a</em> left <em>b</em> number of times</small></li>
</ul>
<ul>
<li>SR : a > b <small class="comment">bit-wise SHIFT-RIGHT (>) operation : shift <em>a</em> right <em>b</em> number of times</small></li>
</ul>
<ul>
<li>RL : a ( b <small class="comment">bit-wise ROTATE-LEFT (() operation : rotate <em>a</em> left <em>b</em> number of times</small></li>
</ul>
<ul>
<li>RR : a ) b <small class="comment">bit-wise ROTATE-LEFT ()) operation : rotate <em>a</em> right <em>b</em> number of times</small></li>
</ul>
<ul>
<li>2's: a' <small class="comment">2's complement (') operation : 2's complement of <em>a</em></small></li>
</ul>
<div style="text-align:center; margin-top: 5em;">
<a href="https://www.producthunt.com/posts/programmer-calculator?utm_source=badge-featured&utm_medium=badge&utm_souce=badge-programmer-calculator" target="_blank"><img style="box-shadow:none; border-radius:0;" src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=281845&theme=light" alt="Programmer Calculator - A command line calculator made for programmers | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" /></a>
</div>
<h4 style="text-align: center; margin-top: 5em; margin-bottom: 0">example usage in iterm panel</h4>
</section>
<div class="imgc">
<img src="assets/panels.png" alt="calculator in panel">
</div>
</body>
</html>