Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (8.1.0)
activesupport (8.1.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.3.1)
Expand All @@ -14,8 +14,8 @@ GEM
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
addressable (2.8.8)
public_suffix (>= 2.0.2, < 8.0)
base64 (0.3.0)
bigdecimal (3.3.1)
coffee-script (2.4.1)
Expand All @@ -25,26 +25,27 @@ GEM
colorator (1.1.0)
commonmarker (0.23.12)
concurrent-ruby (1.3.5)
connection_pool (2.5.4)
connection_pool (3.0.2)
csv (3.3.5)
dnsruby (1.73.0)
dnsruby (1.73.1)
base64 (>= 0.2)
logger (~> 1.6)
simpleidn (~> 0.2.1)
drb (2.2.3)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
ethon (0.17.0)
ethon (0.18.0)
ffi (>= 1.15.0)
logger
eventmachine (1.2.7)
execjs (2.10.0)
faraday (2.14.0)
faraday-net_http (>= 2.0, < 3.5)
json
logger
faraday-net_http (3.4.1)
net-http (>= 0.5.0)
faraday-net_http (3.4.2)
net-http (~> 0.5)
ffi (1.17.2-x64-mingw-ucrt)
ffi (1.17.2-x86_64-linux-gnu)
forwardable-extended (2.6.0)
Expand Down Expand Up @@ -217,7 +218,7 @@ GEM
gemoji (>= 3, < 5)
html-pipeline (~> 2.2)
jekyll (>= 3.0, < 5.0)
json (2.15.1)
json (2.17.1)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
Expand All @@ -232,9 +233,9 @@ GEM
jekyll (>= 3.5, < 5.0)
jekyll-feed (~> 0.9)
jekyll-seo-tag (~> 2.1)
minitest (5.26.0)
net-http (0.6.0)
uri
minitest (5.26.2)
net-http (0.8.0)
uri (>= 0.11.1)
nokogiri (1.18.10-x64-mingw-ucrt)
racc (~> 1.4)
nokogiri (1.18.10-x86_64-linux-gnu)
Expand All @@ -258,7 +259,7 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
sawyer (0.9.2)
sawyer (0.9.3)
addressable (>= 2.3.5)
faraday (>= 0.17.3, < 3)
securerandom (0.4.1)
Expand All @@ -269,12 +270,9 @@ GEM
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2025.2)
tzinfo (>= 1.0.0)
unicode-display_width (1.8.0)
uri (1.0.4)
wdm (0.1.1)
webrick (1.9.1)
uri (1.1.1)
webrick (1.9.2)

PLATFORMS
x64-mingw-ucrt
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ Click [here](https://de-soot.github.io)

### Run Locally

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):
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):
```sh
git clone https://github.com/de-soot/de-soot.github.io
```
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.
3) Once all requirements are installed, run the following command below in a command line terminal:
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.
3. Once all requirements are installed, run the following command below in a command line terminal:
```sh
gem install jekyll bundler
```
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:
4. Now that everything's installed, navigate the terminal to the directory of the copy of the Github repository:
```sh
cd [Path of source code folder]
```
5) Enter this command:
5. Enter this command to preview the site:
```sh
bundle exec jekyll serve
```
6) Navigate to http://localhost:4000 in a browser.
7) Profit!

Refer to the [official Jekyll documentation](https://jekyllrb.com/docs) for more information regarding installing and running Jekyll.
6. Navigate to http://localhost:4000 in a browser.
7. Add your own Markdown posts inside `_posts`.
8. Profit!
4 changes: 2 additions & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
# in the templates via {{ site.myvariable }}.

title: de_soot
github_username: de-soot
description: Hosted on Github Pages
github_username: de-soot
description: Technical blog
baseurl: "" # the subpath of your site, e.g. /blog
url: "https://de-soot.github.io" # the base hostname & protocol for your site, e.g. http://example.com
domain: de-soot.github.io
Expand Down
2 changes: 1 addition & 1 deletion _posts/2025-02-20-groff-apa.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: post
title: Guide to APA with groff ms and refer
date: 2025-02-07
date: 2025-02-20
categories: groff, ms, refer, macro, tmac, APA, style guide, pdf
permalink: /groff-apa
---
Expand Down
38 changes: 38 additions & 0 deletions _posts/2025-12-08-2s-complement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
layout: post
title: 2's Complement Derivation
date: 2025-12-08
categories: cs, binary, bits, negative numbers, derivation, proof, math, 2's complement
permalink: /2s-complement
---

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.

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.

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.

## How Does 2's Complement Work?

Say there is a number `x` represented by `n` binary digits (bits).
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.

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`.
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`.

Rearranging the above equation for `x`, we get `x = (2^n - 1) - ~x`.
It is then easy to find that `-x = -(2^n - 1 - ~x) = -2^n + 1 + ~x`.
Now see the picture of where "flip the bits and add one" comes from.

But we cannot just flip bits and add 1 to get `-x` with ordinary bits, that would just be `~x + 1`.
We are still missing the `-2^n` in the equation, but how would we get that?

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`.
Now all we have to do is define the value of that new bit to be negative to get `-2^n`.
When we flip the bits of `x`, this new bit we added will also get flipped along with it.

## Conclusion

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`.

Hopefully after reading this, you will have gained a better understanding of using 2's complement for converting binary numbers to negative.
10 changes: 5 additions & 5 deletions _site/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1"><!-- Begin Jekyll SEO tag v2.8.0 -->
<title>de_soot | Hosted on Github Pages</title>
<title>de_soot | Technical blog</title>
<meta name="generator" content="Jekyll v3.10.0" />
<meta property="og:title" content="de_soot" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="Hosted on Github Pages" />
<meta property="og:description" content="Hosted on Github Pages" />
<meta name="description" content="Technical blog" />
<meta property="og:description" content="Technical blog" />
<link rel="canonical" href="http://localhost:4000/404.html" />
<meta property="og:url" content="http://localhost:4000/404.html" />
<meta property="og:site_name" content="de_soot" />
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="de_soot" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"WebPage","description":"Hosted on Github Pages","headline":"de_soot","url":"http://localhost:4000/404.html"}</script>
{"@context":"https://schema.org","@type":"WebPage","description":"Technical blog","headline":"de_soot","url":"http://localhost:4000/404.html"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="de_soot" /></head>
<body><header class="site-header" role="banner">
Expand Down Expand Up @@ -75,7 +75,7 @@ <h2 class="footer-heading">de_soot</h2>
</div>

<div class="footer-col footer-col-3">
<p>Hosted on Github Pages</p>
<p>Technical blog</p>
</div>
</div>

Expand Down
21 changes: 10 additions & 11 deletions _site/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# de-soot.github.io

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

## Usage

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

### Run Locally

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):
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):
```sh
git clone https://github.com/de-soot/de-soot.github.io
```
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.
3) Once all requirements are installed, run the following command below in a command line terminal:
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.
3. Once all requirements are installed, run the following command below in a command line terminal:
```sh
gem install jekyll bundler
```
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:
4. Now that everything's installed, navigate the terminal to the directory of the copy of the Github repository:
```sh
cd "{Path of source code folder}"
cd [Path of source code folder]
```
5) Enter this command:
5. Enter this command to preview the site:
```sh
bundle exec jekyll serve
```
6) Navigate to http://localhost:4000 in a browser.
7) Profit!

Refer to the [official Jekyll documentation](https://jekyllrb.com/docs) for more information regarding installing and running Jekyll.
6. Navigate to http://localhost:4000 in a browser.
7. Add your own Markdown posts inside `_posts`.
8. Profit!
8 changes: 4 additions & 4 deletions _site/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
<meta name="generator" content="Jekyll v3.10.0" />
<meta property="og:title" content="About" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="Hosted on Github Pages" />
<meta property="og:description" content="Hosted on Github Pages" />
<meta name="description" content="Technical blog" />
<meta property="og:description" content="Technical blog" />
<link rel="canonical" href="http://localhost:4000/about" />
<meta property="og:url" content="http://localhost:4000/about" />
<meta property="og:site_name" content="de_soot" />
<meta property="og:type" content="website" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="About" />
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"WebPage","description":"Hosted on Github Pages","headline":"About","url":"http://localhost:4000/about"}</script>
{"@context":"https://schema.org","@type":"WebPage","description":"Technical blog","headline":"About","url":"http://localhost:4000/about"}</script>
<!-- End Jekyll SEO tag -->
<link rel="stylesheet" href="/assets/main.css"><link type="application/atom+xml" rel="alternate" href="http://localhost:4000/feed.xml" title="de_soot" /></head>
<body><header class="site-header" role="banner">
Expand Down Expand Up @@ -70,7 +70,7 @@ <h2 class="footer-heading">de_soot</h2>
</div>

<div class="footer-col footer-col-3">
<p>Hosted on Github Pages</p>
<p>Technical blog</p>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion _site/dark-mode.html
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ <h2 class="footer-heading">de_soot</h2>
</div>

<div class="footer-col footer-col-3">
<p>Hosted on Github Pages</p>
<p>Technical blog</p>
</div>
</div>

Expand Down
31 changes: 30 additions & 1 deletion _site/feed.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
<?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>
<?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>

<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>

<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>

<h2 id="how-does-2s-complement-work">How Does 2’s Complement Work?</h2>

<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).
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>

<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>.
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>

<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>.
It is then easy to find that <code class="language-plaintext highlighter-rouge">-x = -(2^n - 1 - ~x) = -2^n + 1 + ~x</code>.
Now see the picture of where “flip the bits and add one” comes from.</p>

<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>.
We are still missing the <code class="language-plaintext highlighter-rouge">-2^n</code> in the equation, but how would we get that?</p>

<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>.
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>.
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>

<h2 id="conclusion">Conclusion</h2>

<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>

<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>

<h1 id="table-of-contents-">Table of Contents <a name="tableofcontents"></a></h1>

Expand Down
Loading