Skip to content

Commit

Permalink
Modify the file structure a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
zeddie888 committed Dec 22, 2022
1 parent ba9beac commit 3ebafea
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ Also (hopefully) a nice read for new [Husky Satellite Lab](https://huskysat.org/
---
## Table of Contents

[src]: src
- [Representing Numbers](notes/numerical-representations.md)
- [Primitive Data Types](notes/primitive-data-types.md)

File renamed without changes
File renamed without changes
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
# Numerical Representation

Contributors: Tri Nguyen

## Introduction to Numbers
___

Numbers form a point of interest in every culture. Sayings like "third times the charm", "four is an unlucky number", or "thirteen is cursed" are things some of us may have heard before.

Therefore, the title of this may sound silly, but let's think for a moment and ask ourselves a question: Why do we represent numbers the way we do? To be more specific, let's look at a following number:

<div style="text-align: center", size="4">

5,973
5,973

</div>

What do each of these digits mean though? Let's write out the full breakdown of the number:<br />

<div style="text-align: center">
<div style="text-align: center">

$$5\times10^3+9\times10^2+7\times10^1+3\times10^0$$

</div>

So let's think about this system we have today. The number of digits we have is 10, ranging from 0 to 9, each "place" is a power of 10, and the places obviously increase by 1 each time. This system is called *decimal* for its use of 10.

This seems like an obvious mathematical fact, but why? Have you ever questioned this format? Specifically, why do we use 10 for all of these?
This seems like an obvious mathematical fact, but why? Have you ever questioned this format? Specifically, why do we use 10 for all of these?

The answer lies in the fact that humans have 10 fingers. From the Chinese to the Arabs to the Romans, every ancient civilization has always counted numbers this way because we have 10 figures, toes, or *digits*. Because of this, many areas of our life rely on this simple fact, from money, politics, and culture.

Expand All @@ -41,7 +43,7 @@ Let's assert that the new species *alans machinicus* has 2 fingers. We therefore

Now let's break this down. Since they only have 2 fingers, they only have 2 options for digits, where we have chosen 0 and 1. Their "places" will be in powers of 2, and the powers will still increase sequentially, so the breakdown is

<div style="text-align: center">
<div style="text-align: center">

$$1\times2^7+0\times2^6+0\times2^5+1\times2^4+1\times2^3+0\times2^2+1\times2^1+0\times2^0$$

Expand Down Expand Up @@ -73,7 +75,7 @@ In this case:

Ignore this if you don't want to nerd out, but the *alans machinicus* would actually expand the above number as:

<div style="text-align: center">
<div style="text-align: center">

$$1_2\times10_2 ^{111_2}+0_2\times10_2^{110_2}+0_2\times10_2^{101_2}+1_2\times10_2^{100_2}+1_2\times10_2^{11_2}+0_2\times10_2^{10}+1_2\times10_2^1+0_2\times10_2^0$$

Expand Down Expand Up @@ -110,15 +112,15 @@ F94A23C5<sub>16</sub>

can be represented as

<div style="text-align: center">
<div style="text-align: center">

$$15\times16^7+9\times16^6+4\times16^5+10\times16^4+2\times16^3+3\times16^2+12\times16^1+5\times16^0$$

</div>

or

<div style="text-align: center">
<div style="text-align: center">

F94A23C5<sub>16</sub> = 4,182,385,605<sub>10</sub>

Expand All @@ -131,31 +133,31 @@ Let's say we have a number in base N. The possible digits range from 0 to N - 1,

One last thing though - You'll run into binary and hexdecimal (And decimal obviously) when working with code at one point or another, and so within coding, they earn a special notation for their numbers. For binary, it is

<div style="text-align: center">
<div style="text-align: center">

0bNumber

</div>

in decimal

<div style="text-align: center">
<div style="text-align: center">

0dNumber

</div>

and in hexdecimal

<div style="text-align: center">
<div style="text-align: center">

0xNumber

</div>

As a final example, let's represent the number 9,096 in all the systems we've learned, in this format!

<div style="text-align: center">
<div style="text-align: center">

0b10001110001000 = 0d9096 = 0x2388

Expand Down
19 changes: 10 additions & 9 deletions Chapters/Primitive_Data_Types.md → notes/primitive-data-types.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Primitive Data Types

Contributors: Tri Nguyen

## Introduction
___
Expand Down Expand Up @@ -64,14 +65,14 @@ Big Endian | The data is organized from left to right, so the MSB is to the left
___
Integers are a bit more complicated than you would think. A positive integer would be represented how you think it would, using the normal conversion discussed in **Numerical Representation**. If an integer is defined in code such that it only supports positive numbers, it is called *unsigned*.

But what about negative integers, or *signed* integers? What happens is that the Most Significant Bit (MSBit) is used to indicate the sign of the digit (1 for negative, 0 for positive). However, it will be in the interest of the computer to be able to directly add binary numbers together, but unfortunately, manipulating the MSBit alone won't cut it.
But what about negative integers, or *signed* integers? What happens is that the Most Significant Bit (MSBit) is used to indicate the sign of the digit (1 for negative, 0 for positive). However, it will be in the interest of the computer to be able to directly add binary numbers together, but unfortunately, manipulating the MSBit alone won't cut it.

----------------
Example 1:

Let's say we're using an 4 bit integer. Its really 3 bits since one is used for the sign. Let us say we want to subtract 4 and 3 in binary. There's two ways of doing this. We can simply subtract them

<div style="text-align: center">
<div style="text-align: center">

$$0100_2-0011_2 = 0001_2 = 1_{10}$$

Expand All @@ -80,7 +81,7 @@ $$0100_2-0011_2 = 0001_2 = 1_{10}$$

However, if we add 4 and -3, watch what happens:

<div style="text-align: center">
<div style="text-align: center">

$$0100_2+1011_2 = 1111_2 = -7_{10}$$

Expand All @@ -98,7 +99,7 @@ Therefore, we need to change up the representation of the negative numbers in ad

If you know the notation for this, it would be:

<div style="text-align: center">
<div style="text-align: center">

$$!(b_2)<<1$$

Expand All @@ -109,7 +110,7 @@ This works regardless of whether b<sub>2</sub> is positive or negative.

In C++, you can represent Integers in many different ways. They can be *unsigned* (*signed* by default), and you can also make them different lengths (8, 16, 32, or 64). For a size N, the syntax is of the form:

<div style="text-align: center">
<div style="text-align: center">

`intN_t` (*signed*)

Expand All @@ -120,7 +121,7 @@ In C++, you can represent Integers in many different ways. They can be *unsigned

For any size N, the range of numbers an integer can represent in decimal is:

<div style="text-align: center">
<div style="text-align: center">

*Signed*: -2<sup>N/2</sup> to 2<sup>N/2 - 1</sup>

Expand All @@ -132,7 +133,7 @@ For any size N, the range of numbers an integer can represent in decimal is:
___
Floats are actually quite different. As a first, these are always signed. But secondly, representing them is very different. We need to form an equivalent to the integer case, so take the decimal number

<div style="text-align: center">
<div style="text-align: center">

15.72
$$1\times10^1+5\times10^0+7\times10^{-1}+2\times10^{-2}$$
Expand Down Expand Up @@ -168,7 +169,7 @@ This is the weakness of a float/double, since they will never be able to accurat

This is arranged such that the resulting float/double number is:

<div style="text-align: center">
<div style="text-align: center">

$$(-1)^{S_2}\times10^{E_2 - O_2}\times(1.M)_2$$

Expand All @@ -180,7 +181,7 @@ This guarentees a very good accuracy of floats/doubles, but you'll sometimes see
## Characters
___
These have a very simple representation, as they are the equivalent of an unsigned integer with less space. A mapping of char to integer values is shown with the following ASCII table:
![](Images/ASCII_Table.png)
![](../images/ascii-table.png)
<div style="text-align: center"> Figure 1 - ASCII Table</div>

## Booleans
Expand Down

0 comments on commit 3ebafea

Please sign in to comment.