User Tools

Site Tools


haas:fall2023:c4eng:projects:dtr0

Corning Community College

ENGR1050 C for Engineers

PROJECT: Data Type Resources (DTR0)

OBJECTIVE

To begin our exploration of programming, starting with an investigation into the various data types available in C, along with their properties, and collaboratively authoring and documenting the project and its specifications.

PROCESS

Do note, the productive way to go about this project involves taking the following steps:

  • starting early
  • reading the project page
  • asking questions regarding things you do not know, are not clear on, or are confused about
  • as information, concepts, processes become clear, that is something you can contribute to the project documentation (so you can better remember)

If you start too late, and do not ask questions, and do not have enough time and don't know what is going on, you are not doing the project correctly.

GRABIT

To assist with consistency across all implementations, data files for use with this project are available on lab46 via the grabit tool. Be sure to obtain it and ensure your implementation properly works with the provided data.

lab46:~/src/SEMESTER/DESIG$ grabit DESIG PROJECT

EDIT

You will want to go here to edit and fill in the various sections of the document:

BACKGROUND

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.

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

The prefix “bi” stands for two. This means that binary uses two numbers to count based on zeroes and ones. Computers use binary to store and manipulate data. Zeroes represents no flow of electricity, whereas one represents electricity being allowed to flow.

The binary number system, also known as base-2, is the numbers used by computers. This uses the numbers 0 and 1 to represent a given value: 000000, 000001, 000010, 000011, 000100, 000101, 000110, 000111, 001000, 001001, 001010, 001011, 001100, 001101, 001110, 001111, 010000 (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, and convert them back into their original number system once finished with these computations. For example, say someone wanted to perform the computation 3 + 2 in the decimal number system. A computer would convert these values into the binary values of 000011 and 000010, respectively, compute the binary value 000101 from these values, and convert this value back into the decimal value of 5.

When you say a binary number, pronounce each digit (example, the binary number “101” is spoken as “one zero one”, or sometimes “one-oh-one”). This way people don't get confused with the decimal number. A single binary digit (like “0” or “1”) is called a “bit”. For example 11010 is five bits long. The word bit is made up from the words “binary digit”

HEXADECIMAL NUMBERS

The prefix “hexa” stands for six, and the prefix “deci” stands for ten, and as such, the combined prefix of “hexadeci” stands for sixteen. This means that hexadecimal uses 16 numbers to count based on both numbers and letters of the English alphabet. Hexadecimal is primarily used when converting large strings of binary numbers used by computers into a lesser number of digits that is more easily understandable to the human eye.

The hexadecimal number system, also known as base-16, uses the numbers 0 through 9 and the English letters A through F to represent a given value: 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10 (These are equivalent to the values 0 through 16 in the decimal number system)

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, these equal 0x05 and 0x0A, respectively, in the hexadecimal number system. Combining these two binary numbers into one number thus yields 0x5A in hexadecimal.

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

Signed char- This type of data occupies 1 byte of memory (8 bits) and allows expressing a maximum of 256 values. Signed char can contain both positive and negative values along with zero. The range of values is from -128 to 127.

Unsigned char- This type of data occupies 1 byte of memory (8 bits) and allows expressing a maximum of 256 values as well. Unlike signed char, unsigned char can only contain positive values and zero. The range of values is from 0 to 255.

Signed short int- This type of data occupies 2 bytes of memory (16 bits) and allows expressing a maximum of 65,536 values as well. Signed short int can contain both positive and negative values along with zero. The range of values is from -32,768 to 32,767.

Unsigned short int- This type of data occupies 2 bytes of memory (16 bits) and allows expressing a maximum of 65,536 values as well. Unlike signed short int, unsigned short int can only contain positive values and zero. The range of values is from 0 to 65,535.

Signed int- This type of data occupies 2 or 4 bytes of memory (16 or 32 bits) depending on the compiler and allows expressing a maximum of 65,536 at 2 bytes or 4,294,967,296 values at 4 bytes. Signed short int can contain both positive and negative values along with zero. The range of values is from -32,768 to 32,767 at 2 bytes or -2,147,483,648 to 2,147,483,647 at 4 bytes.

Unsigned int- This type of data occupies 2 or 4 bytes of memory (16 or 32 bits) depending on the compiler and allows expressing a maximum of 65,536 at 2 bytes or 4,294,967,296 values at 4 bytes. Unsigned short int can contain only positive values along with zero. The range of values is from 0 to 65,535 at 2 bytes or 0 to 4,294,967,295 at 4 bytes.

Signed long int- This type of data occupies 4 or 8 bytes (32 or 64 bits) depending on the compiler and allows expressing a maximum of 4,294,967,295 at 4 bytes or 18,446,744,073,709,551,616 at 8 bytes. Signed long int can contain a range of values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Unsigned long int- This type of data occupies 4 or 8 bytes (32 or 64 bits) depending on the compiler and allows expressing a maximum of 4,294,967,295 at 4 bytes or 18,446,744,073,709,551,616 at 8 bytes. Unsigned long int can contain a range of values from 0 to 18,446,744,073,709,551,615.

Signed long long int- This type of data occupies 2,4 or 8 bytes of memory (16,32 or 64 bits) depending on the compiler and allows expressing a maximum of 65,536 at 2 bytes, 4,294,967,296 values at 4 bytes or 18,446,744,073,709,551,615 at 8 bytes. Signed long long int can contain a range of values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

Unsigned long long int- This type of data occupies 2,4 or 8 bytes of memory (16,32 or 64 bits) depending on the compiler and allows expressing a maximum of 65,536 at 2 bytes, 4,294,967,296 values at 4 bytes or 18,446,744,073,709,551,615 at 8 bytes. Unsigned long long int can contain a range of values from 0 to 18,446,744,073,709,551,615.

Due to the limitations of our Pi's and compiler, the max bit count should be 32, this will mean that un/signed long long and un/signed long types will share values

COMPILE CODE

Command for compiling project dtr0, where dtr0 is your complied code, dtr0.c is what your compiling (nano window) and -lm (math library).

gcc -Wall --std=gnu18 -o dtr0 dtr0.c -lm
PRINTF FORMAT SPECIFIERS

The various printf functions take a format string and optional arguments and produce a formatted sequence of characters for output. In this project there are 2 specifiers that we must include.

First there is the type specifier, the type specifier character specifies how it should interpret the corresponding argument. Should it interpret it as a character, string, pointer, integer, or a float?

Important type specifiers used within this project are;

%hhd- Specifies the output type as half of a half of a signed int (4/2/2 = 1 byte)

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

%u - Specifies the output type as an unsigned int (4 bytes)

%d - Specifies the output type as a signed int (4 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

Essentially, %u and %d are the bases for these, adding H before the u or d will half the byte count, and adding L's will increase the byte count. Within the project, each next data type increases in size. To represent this, you will change the specifier, mainly by increasing the byte count specified.

PROGRAM SPECIFICATIONS

Within dtr0.c you will find multiple sections, commented respective to their task. You will write very similar code for the required sections, each section meant for a different data type in C (and titled appropriately). As an example of the code you'll need, all the tasks for signed char have already been completed. It is your job to study the given code and implement it elsewhere in the program where appropriate to populate sections for each data type, which will be formatted and printed to the terminal.

These sections, when completed, will contain multiple print statements to display information and formatting. They will also contain some computations for determining some of the information that will be printed to the screen. For example, take the following statement:

quantity = (long double) pow (2, (size * 8)); 

This statement informs us of the possible distinct values, which we will need for our output.

To get an idea of what your output should look like for each section, you can compile and run the program before even making any modifications. Notice that there is formatting to align the information in the right “column”. There are seven values paired with their respective textual descriptions to the left. Some of these values are dynamic and computed by our code, and some of these values are static or hard-coded.


If you are leaving nano use this command to save, if you don't you will get a save file every time you return to lab46.

hg commit -m “brief description of changes commit”

Submit

Once your program is complete you will need to submit all your files. To do this, navigate to the directory with your dtr0 program.

cd src/fall2023/c4eng/dtr0

Once you are in the directory, use “ls” to see what files are here. Be sure to include all of these files with your submission.

submit DESIG PROJECT File1 File2 File3 … FileN

 

SUBMISSION

To be successful in this project, the following criteria (or their equivalent) must be met:

  • Project must be submit on time, by the deadline.
    • Late submissions will lose 33% credit per day, with the submission window closing on the 3rd day following the deadline.
  • All code must compile cleanly (no warnings or errors)
    • Compile with the -Wall and –std=gnu18 compiler flags
    • all requested functionality must conform to stated requirements (either on this document or in a comment banner in source code files themselves).
  • Executed programs must display in a manner similar to provided output
    • output formatted, where applicable, must match that of project requirements
  • Processing must be correct based on input given and output requested
  • Output, if applicable, must be correct based on values input
  • Code must be nicely and consistently indented
  • Code must be consistently written, to strive for readability from having a consistent style throughout
  • Code must be commented
    • Any “to be implemented” comments MUST be removed
      • these “to be implemented” comments, if still present at evaluation time, will result in points being deducted.
      • Sufficient comments explaining the point of provided logic MUST be present
  • No global variables (without instructor approval), no goto statements, no calling of main()!
  • Track/version the source code in your lab46 semester repository
  • Submit a copy of your source code to me using the submit tool (make submit on lab46 will do this) by the deadline.

Submit Tool Usage

Let's say you have completed work on the project, and are ready to submit, you would do the following (assuming you have a program called uom0.c):

lab46:~/src/SEMESTER/DESIG/PROJECT$ make submit

You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.

RUBRIC

I'll be evaluating the project based on the following criteria:

26:dtr0:final tally of results (26/26)
*:dtr0:used grabit to obtain project by the Sunday prior to duedate [2/2]
*:dtr0:clean compile, no compiler messages [2/2]
*:dtr0:program conforms to project specifications [20/20]
*:dtr0:code tracked in lab46 semester repo [2/2]

Pertaining to the collaborative authoring of project documentation

  • each class member is to participate in the contribution of relevant information and formatting of the documentation
    • minimal member contributions consist of:
      • near the class average edits (a value of at least four productive edits)
      • near the average class content change average (a value of at least 256 bytes (absolute value of data content change))
      • near the class content contribution average (a value of at least 1kiB)
      • no adding in one commit then later removing in its entirety for the sake of satisfying edit requirements
    • adding and formatting data in an organized fashion, aiming to create an informative and readable document that anyone in the class can reference
    • content contributions will be factored into a documentation coefficient, a value multiplied against your actual project submission to influence the end result:
      • no contributions, co-efficient is 0.50
      • less than minimum contributions is 0.75
      • met minimum contribution threshold is 1.00

Additionally

  • Solutions not abiding by spirit of project will be subject to a 50% overall deduction
  • Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
  • Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction
  • Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction
haas/fall2023/c4eng/projects/dtr0.txt · Last modified: 2023/09/09 07:27 by 127.0.0.1