Fun Trivia | Quizzes | Games | People | Services | Help | Me
Register - Log In
How to Pack a Date in COBOL

Crafted by Trivia Architect denmarks

Fun Trivia : Quizzes : Software and Programming : How to Pack a Date in COBOL

Introduction:
"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."


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?
    Pic Y(4)M(2)D(2)
    Pic date(yyyymmdd)
    Pic date(8)
    Pic X(8)


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?
    The date would take less space.
    The date could be used in a mathematical operation.
    Any letters would be converted to a number.
    All of these.


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


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)
    It can't be done.
    Pic X(8) comp
    Pic 9(8) comp
    Pic 9(4) comp


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)
    Yes
    No


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.
    Yes
    No


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)


8. How many binary digits does it take to store a month? (mm)
    Answer: (Think 1-12)


9. Now let's store our last field. How many binary bits to hold a day? (dd)
    Answer: (Think 1-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?
    Use the COBOL shift bit command.
    Call a subroutine.
    Use powers of 2.
    Great exercise but it can't be done.


report error/typo/spelling mistake (new window)
Copyright, FunTrivia.com. All Rights Reserved.
Legal / Conditions of Use