Introduction to Computing – B142L
Data types
Academic year
2011/12
Objectives:
- Basic data types in the C language
- Comparison of different data types
Digital data
A
bit is the smallest unit of digital data. There are two possible values:
- zero = switch off = low voltage
- one = switch on = high voltage
A combination of multiple bits can be used to store and encode more complex and useful data.
- 8 bits = 1 byte
- 16 bits = 2 bytes = 1 word
Binary encoding of numeric data
The
sum of binary encoded
bits can be used to represent
integer (whole number) values.
Binary encoding of characters
ASCII (
American Standard Code for Information Interchange) is a standard for using binary encoding to represent character symbols.
ASCII uses
8 bits to encode 128 characters:
- 0–31 = control characters
- 32–63 = numbers and punctuation
- 64–95 = uppercase letters
- 96–127 = lowercase letters
Part of the table of ASCII codes:
Source: ASCII. (2011). Retrieved from http://en.wikipedia.org/wiki/Ascii
Basic data types
There are
3 basic data type categories in the C language.
- void
- integer
- char = 1 byte
- short = 2 bytes
- int = 4 bytes
- long = 8 bytes
- floating point
- float = 4 bytes = 6 digits of decimal precision
- double = 8 bytes = 15 digits of decimal precision
- long double = 16 bytes = 18 digits of decimal precision
Basic data types
Data type indicates:
- The amount of memory to allocate, and
- How to interpret the bits of data stored at the allocated location in memory
Data types
increases portability of software between different hardware.
They are
reserved keywords in C.
Data variables
A
data variable has:
- an identifier
- a data type
- a data value
Identifiers in the C language
Identifiers are user friendly names of
variables,
functions and
constants. They are
case sensitive and have no length restrictions. However, they must follow these rules:
- First character must not be a digit
- Consists of a sequence of letters (A-Z, a-z), digits (0-9) and underscores (_)
Boolean values
The C language does
not have a data type for
boolean values of true and false. Instead, it uses the following rules:
- Any value equal to zero is considered to be equivalent to boolean value false.
- Any value not equal to zero is considered to be equivalent to boolean value true.
Review questions
Data types
What is the decimal value of the binary number below?
High order 0 0 1 1 0 0 1 0 Low order
Review questions
Data types
Which is
not a valid data type keyword in the C language?
Review questions
Data types
Which is
not a basic data type category in the C language?