Skip to content

Commit 4f547d4

Browse files
authored
Merge pull request #79 from de-soot/main
new post
2 parents e3e76a5 + a707e94 commit 4f547d4

File tree

14 files changed

+133
-61
lines changed

14 files changed

+133
-61
lines changed

Gemfile.lock

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (8.1.0)
4+
activesupport (8.1.1)
55
base64
66
bigdecimal
77
concurrent-ruby (~> 1.0, >= 1.3.1)
@@ -14,8 +14,8 @@ GEM
1414
securerandom (>= 0.3)
1515
tzinfo (~> 2.0, >= 2.0.5)
1616
uri (>= 0.13.1)
17-
addressable (2.8.7)
18-
public_suffix (>= 2.0.2, < 7.0)
17+
addressable (2.8.8)
18+
public_suffix (>= 2.0.2, < 8.0)
1919
base64 (0.3.0)
2020
bigdecimal (3.3.1)
2121
coffee-script (2.4.1)
@@ -25,26 +25,27 @@ GEM
2525
colorator (1.1.0)
2626
commonmarker (0.23.12)
2727
concurrent-ruby (1.3.5)
28-
connection_pool (2.5.4)
28+
connection_pool (3.0.2)
2929
csv (3.3.5)
30-
dnsruby (1.73.0)
30+
dnsruby (1.73.1)
3131
base64 (>= 0.2)
3232
logger (~> 1.6)
3333
simpleidn (~> 0.2.1)
3434
drb (2.2.3)
3535
em-websocket (0.5.3)
3636
eventmachine (>= 0.12.9)
3737
http_parser.rb (~> 0)
38-
ethon (0.17.0)
38+
ethon (0.18.0)
3939
ffi (>= 1.15.0)
40+
logger
4041
eventmachine (1.2.7)
4142
execjs (2.10.0)
4243
faraday (2.14.0)
4344
faraday-net_http (>= 2.0, < 3.5)
4445
json
4546
logger
46-
faraday-net_http (3.4.1)
47-
net-http (>= 0.5.0)
47+
faraday-net_http (3.4.2)
48+
net-http (~> 0.5)
4849
ffi (1.17.2-x64-mingw-ucrt)
4950
ffi (1.17.2-x86_64-linux-gnu)
5051
forwardable-extended (2.6.0)
@@ -217,7 +218,7 @@ GEM
217218
gemoji (>= 3, < 5)
218219
html-pipeline (~> 2.2)
219220
jekyll (>= 3.0, < 5.0)
220-
json (2.15.1)
221+
json (2.17.1)
221222
kramdown (2.4.0)
222223
rexml
223224
kramdown-parser-gfm (1.1.0)
@@ -232,9 +233,9 @@ GEM
232233
jekyll (>= 3.5, < 5.0)
233234
jekyll-feed (~> 0.9)
234235
jekyll-seo-tag (~> 2.1)
235-
minitest (5.26.0)
236-
net-http (0.6.0)
237-
uri
236+
minitest (5.26.2)
237+
net-http (0.8.0)
238+
uri (>= 0.11.1)
238239
nokogiri (1.18.10-x64-mingw-ucrt)
239240
racc (~> 1.4)
240241
nokogiri (1.18.10-x86_64-linux-gnu)
@@ -258,7 +259,7 @@ GEM
258259
sass-listen (4.0.0)
259260
rb-fsevent (~> 0.9, >= 0.9.4)
260261
rb-inotify (~> 0.9, >= 0.9.7)
261-
sawyer (0.9.2)
262+
sawyer (0.9.3)
262263
addressable (>= 2.3.5)
263264
faraday (>= 0.17.3, < 3)
264265
securerandom (0.4.1)
@@ -269,12 +270,9 @@ GEM
269270
ethon (>= 0.9.0)
270271
tzinfo (2.0.6)
271272
concurrent-ruby (~> 1.0)
272-
tzinfo-data (1.2025.2)
273-
tzinfo (>= 1.0.0)
274273
unicode-display_width (1.8.0)
275-
uri (1.0.4)
276-
wdm (0.1.1)
277-
webrick (1.9.1)
274+
uri (1.1.1)
275+
webrick (1.9.2)
278276

279277
PLATFORMS
280278
x64-mingw-ucrt

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@ Click [here](https://de-soot.github.io)
1010

1111
### Run Locally
1212

13-
1) [Clone](https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories) this github repository onto your computer by simply downloading the source code from this Github repository, or by using [`git`](https://git-scm.com):
13+
1. [Clone](https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories) this github repository onto your computer by simply downloading the source code from this Github repository, or by using [`git`](https://git-scm.com):
1414
```sh
1515
git clone https://github.com/de-soot/de-soot.github.io
1616
```
17-
2) Follow [this guide](https://jekyllrb.com/docs/installation) to install the prerequisites for Jekyll for your system if you have not already done so.
18-
3) Once all requirements are installed, run the following command below in a command line terminal:
17+
2. Follow [this guide](https://jekyllrb.com/docs/installation) to install the prerequisites for Jekyll for your system if you have not already done so.
18+
3. Once all requirements are installed, run the following command below in a command line terminal:
1919
```sh
2020
gem install jekyll bundler
2121
```
22-
4) Now that everything's installed and good to go, navigate the terminal to the directory where the you downloaded the copy of the Github repository, like so:
22+
4. Now that everything's installed, navigate the terminal to the directory of the copy of the Github repository:
2323
```sh
2424
cd [Path of source code folder]
2525
```
26-
5) Enter this command:
26+
5. Enter this command to preview the site:
2727
```sh
2828
bundle exec jekyll serve
2929
```
30-
6) Navigate to http://localhost:4000 in a browser.
31-
7) Profit!
32-
33-
Refer to the [official Jekyll documentation](https://jekyllrb.com/docs) for more information regarding installing and running Jekyll.
30+
6. Navigate to http://localhost:4000 in a browser.
31+
7. Add your own Markdown posts inside `_posts`.
32+
8. Profit!

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
# in the templates via {{ site.myvariable }}.
2020

2121
title: de_soot
22-
github_username: de-soot
23-
description: Hosted on Github Pages
22+
github_username: de-soot
23+
description: Technical blog
2424
baseurl: "" # the subpath of your site, e.g. /blog
2525
url: "https://de-soot.github.io" # the base hostname & protocol for your site, e.g. http://example.com
2626
domain: de-soot.github.io

_posts/2025-02-20-groff-apa.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
33
title: Guide to APA with groff ms and refer
4-
date: 2025-02-07
4+
date: 2025-02-20
55
categories: groff, ms, refer, macro, tmac, APA, style guide, pdf
66
permalink: /groff-apa
77
---

_posts/2025-12-08-2s-complement.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
layout: post
3+
title: 2's Complement Derivation
4+
date: 2025-12-08
5+
categories: cs, binary, bits, negative numbers, derivation, proof, math, 2's complement
6+
permalink: /2s-complement
7+
---
8+
9+
If you have ever taken CS in high school or college, you have probably been taught about how to represent negative numbers in binary using 2's complement.
10+
11+
But teachers generally just tell you to "flip the bits and add one" without really explaining why it works---similar to how high school teachers treat math formulas.
12+
13+
I have never liked memorising without understanding when it comes to learning, so I came up with an intuitive derivation and wrote this blog post to share it in hopes that somebody may find it useful.
14+
15+
## How Does 2's Complement Work?
16+
17+
Say there is a number `x` represented by `n` binary digits (bits).
18+
Since each bit can be `0` or `1`, there are 2^n possible combinations for the string of bits that represent values ranging from zero to 2^n - 1, and thus `x` is always less than 2^n.
19+
20+
If we flip all the bits of `x` using the bitwise NOT operator (`~`), we get a new number with `1` bits where there were `0`'s in `x` and `0` bits where there were `1`'s in `x`.
21+
We will call this new number `~x`, where `x + ~x = 2^n - 1`, since 2^n - 1 has all `n` number of bits set to `1`.
22+
23+
Rearranging the above equation for `x`, we get `x = (2^n - 1) - ~x`.
24+
It is then easy to find that `-x = -(2^n - 1 - ~x) = -2^n + 1 + ~x`.
25+
Now see the picture of where "flip the bits and add one" comes from.
26+
27+
But we cannot just flip bits and add 1 to get `-x` with ordinary bits, that would just be `~x + 1`.
28+
We are still missing the `-2^n` in the equation, but how would we get that?
29+
30+
Currently, since the value of the most significant bit is `2^(n-1)`, if we add another bit from the left, its place value would be `2^(n-1) * 2 = 2^n`.
31+
Now all we have to do is define the value of that new bit to be negative to get `-2^n`.
32+
When we flip the bits of `x`, this new bit we added will also get flipped along with it.
33+
34+
## Conclusion
35+
36+
Putting all the pieces together, we get that for a number `x` represented by `n` bits (with an extra bit having a place value of `-2^n`) where `x = (2^n - 1) - ~x`, you would need to flip its bits and add one to get `-2^n + ~x + 1 = -x`.
37+
38+
Hopefully after reading this, you will have gained a better understanding of using 2's complement for converting binary numbers to negative.

_site/404.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@
33
<meta charset="utf-8">
44
<meta http-equiv="X-UA-Compatible" content="IE=edge">
55
<meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.8.0 -->
6-
<title>de_soot | Hosted on Github Pages</title>
6+
<title>de_soot | Technical blog</title>
77
<meta name="generator" content="Jekyll v3.10.0" />
88
<meta property="og:title" content="de_soot" />
99
<meta property="og:locale" content="en_US" />
10-
<meta name="description" content="Hosted on Github Pages" />
11-
<meta property="og:description" content="Hosted on Github Pages" />
10+
<meta name="description" content="Technical blog" />
11+
<meta property="og:description" content="Technical blog" />
1212
<link rel="canonical" href="http://localhost:4000/404.html" />
1313
<meta property="og:url" content="http://localhost:4000/404.html" />
1414
<meta property="og:site_name" content="de_soot" />
1515
<meta property="og:type" content="website" />
1616
<meta name="twitter:card" content="summary" />
1717
<meta property="twitter:title" content="de_soot" />
1818
<script type="application/ld+json">
19-
{"@context":"https://schema.org","@type":"WebPage","description":"Hosted on Github Pages","headline":"de_soot","url":"http://localhost:4000/404.html"}</script>
19+
{"@context":"https://schema.org","@type":"WebPage","description":"Technical blog","headline":"de_soot","url":"http://localhost:4000/404.html"}</script>
2020
<!-- End Jekyll SEO tag -->
2121
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="de_soot" /></head>
2222
<body><header class="site-header" role="banner">
@@ -75,7 +75,7 @@ <h2 class="footer-heading">de_soot</h2>
7575
</div>
7676

7777
<div class="footer-col footer-col-3">
78-
<p>Hosted on Github Pages</p>
78+
<p>Technical blog</p>
7979
</div>
8080
</div>
8181

_site/README.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# de-soot.github.io
22

3-
A place on the Internet where I write about stuff.
3+
Personal website where I write technical blog posts.
44

55
## Usage
66

@@ -10,24 +10,23 @@ Click [here](https://de-soot.github.io)
1010

1111
### Run Locally
1212

13-
1) [Clone](https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories) this github repository onto your computer by simply downloading the source code from this Github repository, or by using [`git`](https://git-scm.com):
13+
1. [Clone](https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories) this github repository onto your computer by simply downloading the source code from this Github repository, or by using [`git`](https://git-scm.com):
1414
```sh
1515
git clone https://github.com/de-soot/de-soot.github.io
1616
```
17-
2) Follow [this guide](https://jekyllrb.com/docs/installation) to install the prerequisites for Jekyll for your system if you have not already done so.
18-
3) Once all requirements are installed, run the following command below in a command line terminal:
17+
2. Follow [this guide](https://jekyllrb.com/docs/installation) to install the prerequisites for Jekyll for your system if you have not already done so.
18+
3. Once all requirements are installed, run the following command below in a command line terminal:
1919
```sh
2020
gem install jekyll bundler
2121
```
22-
4) Now that everything's installed and good to go, navigate the terminal to the directory where the you downloaded the copy of the Github repository, like so:
22+
4. Now that everything's installed, navigate the terminal to the directory of the copy of the Github repository:
2323
```sh
24-
cd "{Path of source code folder}"
24+
cd [Path of source code folder]
2525
```
26-
5) Enter this command:
26+
5. Enter this command to preview the site:
2727
```sh
2828
bundle exec jekyll serve
2929
```
30-
6) Navigate to http://localhost:4000 in a browser.
31-
7) Profit!
32-
33-
Refer to the [official Jekyll documentation](https://jekyllrb.com/docs) for more information regarding installing and running Jekyll.
30+
6. Navigate to http://localhost:4000 in a browser.
31+
7. Add your own Markdown posts inside `_posts`.
32+
8. Profit!

_site/about.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
<meta name="generator" content="Jekyll v3.10.0" />
88
<meta property="og:title" content="About" />
99
<meta property="og:locale" content="en_US" />
10-
<meta name="description" content="Hosted on Github Pages" />
11-
<meta property="og:description" content="Hosted on Github Pages" />
10+
<meta name="description" content="Technical blog" />
11+
<meta property="og:description" content="Technical blog" />
1212
<link rel="canonical" href="http://localhost:4000/about" />
1313
<meta property="og:url" content="http://localhost:4000/about" />
1414
<meta property="og:site_name" content="de_soot" />
1515
<meta property="og:type" content="website" />
1616
<meta name="twitter:card" content="summary" />
1717
<meta property="twitter:title" content="About" />
1818
<script type="application/ld+json">
19-
{"@context":"https://schema.org","@type":"WebPage","description":"Hosted on Github Pages","headline":"About","url":"http://localhost:4000/about"}</script>
19+
{"@context":"https://schema.org","@type":"WebPage","description":"Technical blog","headline":"About","url":"http://localhost:4000/about"}</script>
2020
<!-- End Jekyll SEO tag -->
2121
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="de_soot" /></head>
2222
<body><header class="site-header" role="banner">
@@ -70,7 +70,7 @@ <h2 class="footer-heading">de_soot</h2>
7070
</div>
7171

7272
<div class="footer-col footer-col-3">
73-
<p>Hosted on Github Pages</p>
73+
<p>Technical blog</p>
7474
</div>
7575
</div>
7676

_site/dark-mode.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ <h2 class="footer-heading">de_soot</h2>
192192
</div>
193193

194194
<div class="footer-col footer-col-3">
195-
<p>Hosted on Github Pages</p>
195+
<p>Technical blog</p>
196196
</div>
197197
</div>
198198

_site/feed.xml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
1-
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2025-12-04T17:22:50+08:00</updated><id>http://localhost:4000/feed.xml</id><title type="html">de_soot</title><subtitle>Hosted on Github Pages</subtitle><entry><title type="html">Guide to APA with groff ms and refer</title><link href="http://localhost:4000/groff-apa" rel="alternate" type="text/html" title="Guide to APA with groff ms and refer" /><published>2025-02-07T00:00:00+08:00</published><updated>2025-02-07T00:00:00+08:00</updated><id>http://localhost:4000/groff-apa</id><content type="html" xml:base="http://localhost:4000/groff-apa"><![CDATA[<p>This guide explains why and how I used groff with the ms and refer macros to write my college essay in Neovim.</p>
1+
<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="http://localhost:4000/feed.xml" rel="self" type="application/atom+xml" /><link href="http://localhost:4000/" rel="alternate" type="text/html" /><updated>2025-12-08T21:47:51+08:00</updated><id>http://localhost:4000/feed.xml</id><title type="html">de_soot</title><subtitle>Technical blog</subtitle><entry><title type="html">2’s Complement Derivation</title><link href="http://localhost:4000/2s-complement" rel="alternate" type="text/html" title="2’s Complement Derivation" /><published>2025-12-08T00:00:00+08:00</published><updated>2025-12-08T00:00:00+08:00</updated><id>http://localhost:4000/2s-complement</id><content type="html" xml:base="http://localhost:4000/2s-complement"><![CDATA[<p>If you have ever taken CS in high school or college, you have probably been taught about how to represent negative numbers in binary using 2’s complement.</p>
2+
3+
<p>But teachers generally just tell you to “flip the bits and add one” without really explaining why it works—similar to how high school teachers treat math formulas.</p>
4+
5+
<p>I have never liked memorising without understanding when it comes to learning, so I came up with an intuitive derivation and wrote this blog post to share it in hopes that somebody may find it useful.</p>
6+
7+
<h2 id="how-does-2s-complement-work">How Does 2’s Complement Work?</h2>
8+
9+
<p>Say there is a number <code class="language-plaintext highlighter-rouge">x</code> represented by <code class="language-plaintext highlighter-rouge">n</code> binary digits (bits).
10+
Since each bit can be <code class="language-plaintext highlighter-rouge">0</code> or <code class="language-plaintext highlighter-rouge">1</code>, there are 2^n possible combinations for the string of bits that represent values ranging from zero to 2^n - 1, and thus <code class="language-plaintext highlighter-rouge">x</code> is always less than 2^n.</p>
11+
12+
<p>If we flip all the bits of <code class="language-plaintext highlighter-rouge">x</code> using the bitwise NOT operator (<code class="language-plaintext highlighter-rouge">~</code>), we get a new number with <code class="language-plaintext highlighter-rouge">1</code> bits where there were <code class="language-plaintext highlighter-rouge">0</code>’s in <code class="language-plaintext highlighter-rouge">x</code> and <code class="language-plaintext highlighter-rouge">0</code> bits where there were <code class="language-plaintext highlighter-rouge">1</code>’s in <code class="language-plaintext highlighter-rouge">x</code>.
13+
We will call this new number <code class="language-plaintext highlighter-rouge">~x</code>, where <code class="language-plaintext highlighter-rouge">x + ~x = 2^n - 1</code>, since 2^n - 1 has all <code class="language-plaintext highlighter-rouge">n</code> number of bits set to <code class="language-plaintext highlighter-rouge">1</code>.</p>
14+
15+
<p>Rearranging the above equation for <code class="language-plaintext highlighter-rouge">x</code>, we get <code class="language-plaintext highlighter-rouge">x = (2^n - 1) - ~x</code>.
16+
It is then easy to find that <code class="language-plaintext highlighter-rouge">-x = -(2^n - 1 - ~x) = -2^n + 1 + ~x</code>.
17+
Now see the picture of where “flip the bits and add one” comes from.</p>
18+
19+
<p>But we cannot just flip bits and add 1 to get <code class="language-plaintext highlighter-rouge">-x</code> with ordinary bits, that would just be <code class="language-plaintext highlighter-rouge">~x + 1</code>.
20+
We are still missing the <code class="language-plaintext highlighter-rouge">-2^n</code> in the equation, but how would we get that?</p>
21+
22+
<p>Currently, since the value of the most significant bit is <code class="language-plaintext highlighter-rouge">2^(n-1)</code>, if we add another bit from the left, its place value would be <code class="language-plaintext highlighter-rouge">2^(n-1) * 2 = 2^n</code>.
23+
Now all we have to do is define the value of that new bit to be negative to get <code class="language-plaintext highlighter-rouge">-2^n</code>.
24+
When we flip the bits of <code class="language-plaintext highlighter-rouge">x</code>, this new bit we added will also get flipped along with it.</p>
25+
26+
<h2 id="conclusion">Conclusion</h2>
27+
28+
<p>Putting all the pieces together, we get that for a number <code class="language-plaintext highlighter-rouge">x</code> represented by <code class="language-plaintext highlighter-rouge">n</code> bits (with an extra bit having a place value of <code class="language-plaintext highlighter-rouge">-2^n</code>) where <code class="language-plaintext highlighter-rouge">x = (2^n - 1) - ~x</code>, you would need to flip its bits and add one to get <code class="language-plaintext highlighter-rouge">-2^n + ~x + 1 = -x</code>.</p>
29+
30+
<p>Hopefully after reading this, you will have gained a better understanding of using 2’s complement for converting binary numbers to negative.</p>]]></content><author><name></name></author><category term="cs," /><category term="binary," /><category term="bits," /><category term="negative" /><category term="numbers," /><category term="derivation," /><category term="proof," /><category term="math," /><category term="2&apos;s" /><category term="complement" /><summary type="html"><![CDATA[If you have ever taken CS in high school or college, you have probably been taught about how to represent negative numbers in binary using 2’s complement.]]></summary></entry><entry><title type="html">Guide to APA with groff ms and refer</title><link href="http://localhost:4000/groff-apa" rel="alternate" type="text/html" title="Guide to APA with groff ms and refer" /><published>2025-02-20T00:00:00+08:00</published><updated>2025-02-20T00:00:00+08:00</updated><id>http://localhost:4000/groff-apa</id><content type="html" xml:base="http://localhost:4000/groff-apa"><![CDATA[<p>This guide explains why and how I used groff with the ms and refer macros to write my college essay in Neovim.</p>
231
332
<h1 id="table-of-contents-">Table of Contents <a name="tableofcontents"></a></h1>
433

0 commit comments

Comments
 (0)