Compare and Contrast Fundamental Data Types and Their Characteristics
Date: Aug 25, 2019
In this sample chapter from CompTIA IT Fundamentals+ FC0-U61 Cert Guide, you will learn how to compare and contrast fundamental data types and their characteristics: char, strings, numbers (integers and floats), and Boolean.
Whether you’re programming, crunching numbers with spreadsheets, or figuring out binary logic, understanding the fundamental data types used by Information Technology is foundational. In this chapter, you learn about IT Fundamentals+ Objective 1.2: Compare and contrast fundamental data types and their characteristics: char, strings, numbers (integers and floats), and Boolean.
Foundation Topics
Char
Char is an abbreviation for character. Many programming languages use char as a reserved keyword, including Visual Basic, SQL, Java, C languages, and others. Char is a data type that refers to a single character or a single-character variable. For example, each of the following is a char data type:
1
2
A
Z
x
#
!
A char is equal to 1 byte.
Strings
A string is a series of characters that is interpreted literally by a script, such as “Abraham Lincoln” or “THX1138.” Computer programs usually connect a string to a variable. For example:
$string = "This is a string" Print "The value of $string is " $string Output: The value of $string is This is a string
In this example, the variable $string is assigned the value "This is a string". Then, the second line prints “The value of $string is This is a string” when the script is run.
The amount of space set aside for a string can be variable (enabling strings of various lengths) or fixed. If a string has a length of 11 characters, but you attempt to enter more than 11 characters, the last characters will be left off. This is called truncation. Figure 3-1 illustrates an example of this problem.
Figure 3-1 Example of a Truncation
When data entry systems are designed to use fixed-size strings, watch out for truncation like this example. Data entry designers need to take into account both typical and larger examples of proper names or other data when sizing data entry fields.
Numbers
The common data types used for numbers include the following:
Integers
Floats
Integers
An integer (also known as int) is a positive or negative whole number (a number with no decimal points or fractions). For example, the following are positive integers: 3, 4096, and 65535. The following are negative integers (–2, –64, and –98765). What about 0? It’s also an integer.
The INT function in most programming languages drops the decimal or fractional value of a number such as 3.6 and leaves only the whole value (in this case, 3). This can be useful to obtain a whole number value after randomizing a range of numbers. The following example is written in Perl:
my $randnum = int(rand(100)); # int(rand(100)) discards decimal portion of randomized number print "Here's a random number between 0 and 100: $randnum\n";
Floats
A float (also known as floating-point number) is a number that contains up to seven digits and has at least one decimal place. For example, the following are floats:
5.56
.0275687
3.14159
.303
A float is a single-precision, floating-point, 32-bit value.
Floats can also be expressed using powers of ten or powers of two. This way, a fixed number of digits can be used to express a very wide range of numeric values. Here are some examples:
93.1×105 = 9,310,000
93.1×10-5 = 0.000931
93.1×1016 = 931,000,000,000,000,000
93.1×10-16 = 0.00000000000000931
47.67×212 = 47,670,000,000,000
47.67×2-12 = 0.00000000004767
Singe-precision and double-precision floating point numbers are actually approximations of the true value of a number because of the rounding that takes place when non-integer numbers are used. The floating-point calculator at https://www.exploringbinary.com/floating-point-converter/ demonstrates this fact.
Boolean
Boolean values are used in Boolean logic, which evaluates whether a given condition is true (1) or false (0). These values are binary. In computers and other electronic devices, Boolean logic is used to determine if a circuit is charged or on (1) or not charged or off (0). Boolean logic can be used for searches. Boolean logic includes the following comparisons: AND, OR, NOT, and XOR, among others.
AND, OR, NOT, and XOR are used to compare two values.
AND: If both values 1 and 2 exist in a statement, the statement is TRUE. If only value 1 or value 2 exists in a statement, the statement is FALSE.
OR: If either value 1 or 2 exists in a statement, the statement is TRUE.
NOT: If neither value 1 nor 2 exists in a statement, the statement is TRUE. If either or both exist, the statement is FALSE.
XOR: If either value 1 or value 2 exists in a statement, the statement is true. If both exist, or if neither exists, the statement is FALSE.
Boolean logic is often used in performing searches online and elsewhere. Here are the results of a search of a local library’s book and media holdings:
railroad – 244 titles
steam – 273 titles
railroad AND steam – 2 titles
railroad OR steam – 347 titles
railroad NOT steam – 240 titles
Boolean algebra applies Boolean logic to solve equations, such as the following:
If x=1 AND y=1: x AND y=1
If x=1 OR y=0: x OR y=1
x=0: NOT x=1
Boolean logic can be visualized using Venn diagrams. Figure 3-2 illustrates how a Venn diagram can be used to show the product lines of three major component manufacturers: Intel, AMD, and NVIDIA.
Figure 3-2 An Example of a Venn Diagram
The Venn diagram in this figure shows that Intel makes SSDs, whereas AMD does not make SSDs. Both Intel and AMD make motherboard chipsets and CPUs. Both AMD and NVIDIA make graphics processors (GPUs). NVIDIA does not make SSDs, chipsets, or CPUs. Intel does not make GPUs.
Exam Preparation Topics
Review Topics
Review the most important topics in this chapter, noted with the Key Topics icon in the outer margin of the page. Table 3-1 lists these key topics and the page number on which each is found.
Table 3-1 Key Topics for Chapter 3
Key Topic Element |
Description |
Page Number |
Paragraph |
Strings |
27 |
Example of a Truncation |
28 |
|
Paragraph |
Integers |
29 |
Paragraph |
Floats |
29 |
Paragraph |
Booleans |
30 |
Define Key Terms
Define the following key terms from this chapter and check your answers in the glossary:
Char
strings
integers
floats
Boolean
Practice Questions for Objective 1.2
The values 47.67, 8.21, and .7352 are examples of which of the following?
Floats
Integers
Boolean
strings
Which of the following is true about a float?
A float is a 64-bit, single-precision data type.
It has at least seven digits.
It has at least one decimal point.
It cannot be expressed using powers of two.
When multiplying a number that is greater than zero (0) by a negative exponent, which of the following is correct about the result?
The result is a negative number.
The number of decimals equals the number in the exponent.
The result is a positive number.
The digits in the original value are never present in the answer.
You are creating a Boolean search that is looking for information that matches both of your search terms. Which of the following do you use between the terms?
AND
LIKE
OR
NOT
Which of the following equations is correct?
IF x=4 OR y=4, then x<>4
IF x=0 AND y<0, then x>y
IF a≠b OR b≠c, then a=c
IF NOT a=b, then b=c
Which of the following is true about the char data type?
It can only be used for calculation.
It can represent a variable.
It cannot be used for calculation.
It can occupy more than one byte.
You are attempting to enter the phrase “wide world of sports” into a data entry field that can only accept 12 characters. Which of the following is what you will see when you enter this text?
wide world o
ld of sports
wide sports
de world of
Which of the following is an int?
Lincoln
3.14159
84
4/3
Which of the following orders would you use at the Boolean Hamburger stand if you want to get a burger with pickle and ketchup but no mustard or onions?
Burger AND pickle AND ketchup OR mustard OR onions
Burger AND pickle NOT ketchup OR mustard OR onions
Burger AND mustard OR onions NOT ketchup OR pickle
Burger AND ketchup AND pickle NOT mustard NOT onions
You are specifying a data entry system that needs to have enough room for a user to enter a phone number, including area code. The data entry app will automatically put in the parentheses and dashes as needed. Which of the following specifications will allow correct telephone number data entry?
Ten alphanumeric characters
Fourteen numeric characters
Eleven numeric characters
Twelve alphanumeric characters
Which data type refers to a single character or a single-character variable?
Strings
Numbers
Char
Boolean
Which type of logic is used to determine if a circuit is charged or on (1) or not charged or off (0)?
Integers
Strings
Floats
Boolean
Which of the following can be expressed using powers of ten or powers of two?
Boolean
Floats
Strings
Char
If a string has a length of 11 characters and you attempt to enter more than 11 characters, the last characters will be left off. What is this called?
Truncation
Boolean logic
Char overflow
Floating-point
What are numbers with floating-point decimals that contain more than seven digits and up to 15 digits total known as?
Logic gate
64-bit single precision
Double or double-precision
Boolean algebra
Your Next Steps (More Certs)
If data types excite you, you might be on the road to being a programmer or database designer. Along the way, you might want to pick up the CompTIA A+, Network+, and Security+ certifications. Specific certifications in the database arena are available from IBM, Microsoft SQL, Oracle, and SAP.