This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
notes:cprog:fall2022:projects:dtr0 [2022/08/28 14:29] – created wedge | notes:cprog:fall2022:projects:dtr0 [2022/09/08 02:44] (current) – [DATA TYPES IN C] rspringe | ||
---|---|---|---|
Line 3: | Line 3: | ||
====BINARY NUMBERS==== | ====BINARY NUMBERS==== | ||
+ | Also known as the "Base 2" number system, binary is the lowest level of machine language and the language that computers use to receive, perform, and send instructions. | ||
+ | |||
+ | ===Digits and Counting=== | ||
+ | |||
+ | Since binary is "Base 2", it only uses two digits to represent its numbers: 0 and 1. | ||
+ | |||
+ | Counting in binary works the same way as it does in decimal (Base 10), or any other number system: each spot, or " | ||
+ | |||
+ | For example: 1001 + 1 = 1010 | ||
+ | |||
+ | This is just like decimal, where a number starts at 0, then counts up to 9, if we try to count up after that, the number carries over to the Tens place, and restarts at 0: | ||
+ | |||
+ | 109 + 1 = 110 | ||
+ | |||
+ | **NOTE:** Just because a binary number uses similar digits to decimal and looks similar to decimal, it does not mean that a binary number can just be read as a decimal number. | ||
+ | |||
+ | To put it another way: | ||
+ | |||
+ | 1010< | ||
+ | |||
+ | Since decimal is "Base 10", each place in a number is a power of ten, 10< | ||
+ | |||
+ | The same is true for binary, but since it is Base 2, each place is a power of 2: 2< | ||
+ | |||
+ | ===Use in Computing=== | ||
+ | |||
+ | Binary is important because it is the number system and language that computers use to communicate. Any set of instructions sent to a computer will consist of only 1's and 0's. | ||
+ | |||
+ | Although binary is what computers use to communicate, | ||
+ | |||
+ | As stated above, each place in a binary number can only be a 1 or 0, which means each place is a power of 2. So a decimal number like 257 would be 100000001 in binary, as we can see, numbers can get very big, very fast. | ||
+ | |||
+ | With a number system where even simple numbers and code can become a massive amount of 1's and 0's, it is very difficult to perform calculations on these numbers without making a mistake. So, programmers have used higher base numbering systems to shorten these numbers down immensely. These numbering systems are also powers of 2, in order to cleanly split binary numbers into smaller segments, such as octal (Base 8), or hexadecimal (Base 16). | ||
====HEXADECIMAL NUMBERS==== | ====HEXADECIMAL NUMBERS==== | ||
=====DATA TYPES IN C===== | =====DATA TYPES IN C===== | ||
+ | ===Basic Types=== | ||
+ | |||
+ | They are arithmetic types and are further classified into: (a) integer types and (b) floating-point types. | ||
+ | --------------------------------------------------------------------------------------------------------------------- | ||
+ | |||
+ | ===Enumerated Types=== | ||
+ | |||
+ | They are again arithmetic types and they are used to define variables that can only assign certain discrete integer values throughout the program. | ||
+ | --------------------------------------------------------------------------------------------------------------------- | ||
+ | |||
+ | ===The " | ||
+ | |||
+ | The type specifier " | ||
+ | --------------------------------------------------------------------------------------------------------------------- | ||
+ | |||
+ | ===Derived Types=== | ||
+ | They include (a) Pointer types, (b) Array types, (c) Structure types, (d) Union types and (e) Function types. | ||
====PRINTF FORMAT SPECIFIERS==== | ====PRINTF FORMAT SPECIFIERS==== | ||
=====PROGRAM SPECIFICATIONS===== | =====PROGRAM SPECIFICATIONS===== | ||