FREE! Click here to Join FunTrivia. Thousands of games, quizzes, and lots more!
Quiz about How to Pack a Date in COBOL
Quiz about How to Pack a Date in COBOL

How to Pack a Date in COBOL Trivia Quiz


In the early days of computers, space was very limited. It was a challenge to store items in as few bytes as possible. This quiz is about the lower limits for storing a date in a COBOL program.

A multiple-choice quiz by denmarks. Estimated time: 6 mins.
  1. Home
  2. »
  3. Quizzes
  4. »
  5. Science Trivia
  6. »
  7. Computers
  8. »
  9. Software and Programming

Author
denmarks
Time
6 mins
Type
Multiple Choice
Quiz #
234,091
Updated
Dec 03 21
# Qns
10
Difficulty
Difficult
Avg Score
5 / 10
Plays
567
- -
Question 1 of 10
1. The most direct way to store a date is to use an alphanumeric format. You store it as YYYYMMDD in 8 bytes. What is the COBOL definition of this field? Hint


Question 2 of 10
2. Instead of an alphanumeric definition of a date we can use Pic 9(8). Assuming no further modifiers, what would be the advantage over alphanumeric? Hint


Question 3 of 10
3. If we are limited to 5 bytes of storage, is there be a way to store a complete 8 digit date? (yyyymmdd)


Question 4 of 10
4. Let's try an even smaller space. What if we only have 4 bytes available? Choose a format that would allow an 8 digit date. (yyyymmdd) Hint


Question 5 of 10
5. Now let's go to the extreme. You only have 2 bytes available. Can you store an 8 digit date as an 8 digit number? (yyyymmdd)


Question 6 of 10
6. Let's say that the user said it was ok to remove the century from the year. Now there are only 6 digits. (yymmdd) Is there any way to store it in 2 bytes? Look at all possibilities.


Question 7 of 10
7. Now we are just going to refer to binary bits without any consideration of computer storage. How many bits would it take to store a 2 digit year? (yy)

Answer: (Think 0-99)
Question 8 of 10
8. How many binary digits does it take to store a month? (mm)

Answer: (Think 1-12)
Question 9 of 10
9. Now let's store our last field. How many binary bits to hold a day? (dd)

Answer: (Think 1-31)
Question 10 of 10
10. We have three sets of binary bits. Year yyyyyyy; Month mmmm; and Day ddddd. That is a total of 16 bits that will will fit into 2 bytes. How can we create the actual value to move into the 2 bytes using COBOL? Hint



(Optional) Create a Free FunTrivia ID to save the points you are about to earn:

arrow Select a User ID:
arrow Choose a Password:
arrow Your Email:




Quiz Answer Key and Fun Facts
1. The most direct way to store a date is to use an alphanumeric format. You store it as YYYYMMDD in 8 bytes. What is the COBOL definition of this field?

Answer: Pic X(8)

The data definition in COBOL tells the system how many bytes of storage is required and the format of a field. Each "X" in a Pic is 1 byte of storage of an alphanumeric item. A number in parenthesis is a repetition factor.
2. Instead of an alphanumeric definition of a date we can use Pic 9(8). Assuming no further modifiers, what would be the advantage over alphanumeric?

Answer: The date could be used in a mathematical operation.

When "9" is used rather than "x" in a data definition the field is defined as numeric and can be used in a math operation. This would include being able to add or subtract days from the date. If a letter was included in error, the program would crash. It is always best to validate all input fields before doing any math.
3. If we are limited to 5 bytes of storage, is there be a way to store a complete 8 digit date? (yyyymmdd)

Answer: Yes

Instead of defining the field as just Pic 9(8) we add the modifier COMP-3. This indicates that the number is to be stored as binary coded decimal (BCD) or packed. One digit is stored in place of each hex digit. Since a byte is 8 bits or 2 hex digits, 2 BDC digits can be stored.

A sign is stored as the last character and padding is adding to the beginning. The date would look like 020060504F with 2 characters in each byte. A sign of C is positive, D is nevative, and F is unsigned.
4. Let's try an even smaller space. What if we only have 4 bytes available? Choose a format that would allow an 8 digit date. (yyyymmdd)

Answer: Pic 9(8) comp

The comp field is used to store in binary. A 5-9 digit decimal number will fit into a 4 byte binary number. That would be 32 binary bits. Multiply it out and see.
5. Now let's go to the extreme. You only have 2 bytes available. Can you store an 8 digit date as an 8 digit number? (yyyymmdd)

Answer: No

With 8 digits there is no way to store it in 2 bytes as a "number".
6. Let's say that the user said it was ok to remove the century from the year. Now there are only 6 digits. (yymmdd) Is there any way to store it in 2 bytes? Look at all possibilities.

Answer: Yes

You can't store it as a 6 digit number but by manipulating bits to rid yourself of unused number ranges it can be done.
7. Now we are just going to refer to binary bits without any consideration of computer storage. How many bits would it take to store a 2 digit year? (yy)

Answer: 7

A year can run from 00 to 99. A 7 digit binary number can handle 0-127.
8. How many binary digits does it take to store a month? (mm)

Answer: 4

A month is 1-12. Four bits will hold 0-15.
9. Now let's store our last field. How many binary bits to hold a day? (dd)

Answer: 5

A day is 1-31. Five bits will hold 0-31.
10. We have three sets of binary bits. Year yyyyyyy; Month mmmm; and Day ddddd. That is a total of 16 bits that will will fit into 2 bytes. How can we create the actual value to move into the 2 bytes using COBOL?

Answer: Call a subroutine.

This was an actual problem that we had in a bank I worked for about 30 years ago. COBOL does not have the ability to combine or shift bits. You can't do it mathematically since binary numbers are stored with a sign in the first bit. An assembly language subroutine was written to do it that just manipulated the bits and needed no mathematical sign.
Source: Author denmarks

This quiz was reviewed by FunTrivia editor crisw before going online.
Any errors found in FunTrivia content are routinely corrected through our feedback system.
12/22/2024, Copyright 2024 FunTrivia, Inc. - Report an Error / Contact Us