<commit_before>---
published: true
title: 3.5.4 - Binary number system
layout: post
category: computing
tags: CS3.5
---

# Signed / Unsigned

**Signed binary** is binary that can be positive or negative, so it can be two's complement for a negative number or anything else for a positive number. The values of these range from \`-2 ^ {n - 1}\` to \`2 ^ n\` where \`n\` is the number of bits.

**Unsigned binary** is binary that can only be positive, so it has double the range of signed binary. The values of these range from \`0\` to \`2 ^ n - 1\` where n is the number of bits.

# Negation

To get the negative of a binary number, invert the bits and add one. For example:

```
* 0101 0001 ( 81)
~ 0101 0001 =
  1010 1110 (-82)

  1010 1110 (-82)
- 0000 0001 (1)
  ---------
  1010 1111 (-81)
```

# Addition
<commit_msg>Format even better<commit_after>---
published: true
title: 3.5.4 - Binary number system
layout: post
category: computing
tags: CS3.5
---

# Signed / Unsigned

**Signed binary** is binary that can be positive or negative, so it can be two's complement for a negative number or anything else for a positive number. The values of these fall in the range  \`-2 ^ {n - 1} \leq x \leq 2 ^ {n - 1}\` where \`n\` is the number of bits.

**Unsigned binary** is binary that can only be positive, so it has double the range of signed binary. The values of these fall in the range \`0 \leq x \leq 2 ^ n - 1\` where \`n\` is the number of bits.

# Negation

To get the negative of a binary number, invert the bits and add one. For example:

```
* 0101 0001 ( 81)
~ 0101 0001 =
  1010 1110 (-82)

  1010 1110 (-82)
- 0000 0001 (1)
  ---------
  1010 1111 (-81)
```

# Addition

{'fraction_non_alphanumeric': 0.12040332147093713, 'fraction_numerical': 0.08125741399762752, 'mean_word_length': 2.860411899313501, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5374525', 'n_tokens_mistral': 649, 'n_tokens_neox': 547, 'n_words': 277}