This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:c4eng:fall2022:projects:dtr0 [2022/09/06 16:28] – [PRINTF FORMAT SPECIFIERS] cmillica | notes:c4eng:fall2022:projects:dtr0 [2023/09/08 14:31] (current) – [BINARY NUMBERS] nbutler5 | ||
---|---|---|---|
Line 3: | Line 3: | ||
Number systems are a way in which one can represent quantitative values. Certain number systems are used for certain applications. | Number systems are a way in which one can represent quantitative values. Certain number systems are used for certain applications. | ||
- | For example, the decimal number system, also known as base-10, is our typical counting numbers used in daily math. This uses the numbers 0 through 9 to represent a given value: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 | + | For example, the decimal number system, also known as base-10, is our typical counting numbers used in daily math. This uses the numbers 0 through 9 to represent a given value: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16. |
+ | |||
+ | Yet, there are still more number systems that are used. Besides decimal (which is most common) there is hexadecimal which is base-16, octal which is base-8, and binary which is base-2. | ||
====BINARY NUMBERS==== | ====BINARY NUMBERS==== | ||
Line 11: | Line 13: | ||
(These are equivalent to the values 0 through 16 in the decimal number system) | (These are equivalent to the values 0 through 16 in the decimal number system) | ||
- | Computers will always convert the numbers from any number system into binary for the purposes of consistent computation, | + | Computers will always convert the numbers from any number system into binary for the purposes of consistent computation, |
+ | |||
+ | When you say a binary number, pronounce each digit (example, the binary number " | ||
+ | A single binary digit (like " | ||
+ | For example 11010 is five bits long. | ||
+ | The word bit is made up from the words " | ||
====HEXADECIMAL NUMBERS==== | ====HEXADECIMAL NUMBERS==== | ||
Line 19: | Line 26: | ||
Because the hexadecimal base of 16 can also be written as 2^4, this makes converting between binary and hexadecimal much more intuitive than that of decimal. Each digit of the hexadecimal number system can be represented by a specific set of four digits in the binary number system. One can represent larger hexadecimal values in binary by combining strings of binary numbers in these sets of four digits. For example, let's take the binary number 01011010. This binary number can be split into two smaller binary numbers, 0101 and 1010, each with four digits. Individually, | Because the hexadecimal base of 16 can also be written as 2^4, this makes converting between binary and hexadecimal much more intuitive than that of decimal. Each digit of the hexadecimal number system can be represented by a specific set of four digits in the binary number system. One can represent larger hexadecimal values in binary by combining strings of binary numbers in these sets of four digits. For example, let's take the binary number 01011010. This binary number can be split into two smaller binary numbers, 0101 and 1010, each with four digits. Individually, | ||
+ | |||
+ | In hex, four digits of a binary number can be represented by a single hex digit. Dividing a binary number into 4-bit sets means that each set can have a possible value of between 0000 and 1111, allowing 16 number combinations from 0 to 15. With the base value as 16, the maximum value of a digit is 15. | ||
=====DATA TYPES IN C===== | =====DATA TYPES IN C===== | ||
Line 40: | Line 49: | ||
Important type specifiers used within this project are; | Important type specifiers used within this project are; | ||
- | **%d**- Specifies the output type as signed int | + | **%hhd**- Specifies the output type as half of a half of a signed int (4/2/2 = 1 byte) |
- | **%u**- Specifies the output type as unsigned int | + | |
+ | **%hhu**- Specifies the output type as half of a half of an unsigned int (4/2/2 = 1 byte) | ||
+ | |||
+ | **%hd** - Specifies the output type as a half of a signed int (4/2 = 2 bytes) | ||
+ | |||
+ | **%hu** - Specifies the output type as half of an unsigned int (4/2 =2 bytes) | ||
+ | |||
+ | **%lld**- Specifies the output type as a signed long long int | ||
+ | |||
+ | **%llu**- Specifies the output type as an unsigned long long int | ||
**%p**- Specifies the output type as an address in hexadecimal digits | **%p**- Specifies the output type as an address in hexadecimal digits | ||
=====PROGRAM SPECIFICATIONS===== | =====PROGRAM SPECIFICATIONS===== | ||