How to represent information inside the computer
 

The principle of information representation inside the computer:

  • Code + Context = Information

    I.e.: information is represented by a code that must be interpreted with the correct context

    The correct context must be used in order to extract the correct information

 

 

I will show you some examples on how to represent information next

(1) Example on how to represent "sex" information
 

Example: how to represent "sex" information

  • We can encode the sex information of people as follows:

          0  =  male
          1  =  female                    
      

    I.e.: we agree that when storing "sex" information, we use 0 to represent "male" and 1 to represent "female"

 

Note:   this is an example of the use of codes to present information !!!

(2) Example on how to represent "marital status" information
 

Example: how to represent "marital status" information

  • We can encode the marital status information of people as follows:

          0  =  single
          1  =  married
          2  =  divorced
          3  =  widowed                    
      

    I.e.: we agree that when storing "marital status" information, we use 0 to represent "single", 1 to represent "married", and so on

 

Note:   I used decimal number (0,1,2,3) for simplicity.
Computers will use binary numbers: 00, 01, 10 and 11

The importance of contex to interpret information code
 

An example to illustrate the importance of the context:

  • You are given the the sex and marital status information on 2 persons:

         Name  
         -------------------------------
          A           1           0
          B           0           1              
      

    Can you tell the sex and marital status information of person A ???

 

 

The importance of contex to interpret information code
 

An example to illustrate the importance of the context:

  • You are given the the sex and marital status information on 2 persons:

         Name
         -------------------------------
          A           1           0
          B           0           1              
      

    Can you tell the sex and marital status information of person A ???

 

No:   we no not have the context needed to interpret the code ( 0 and 1)

The importance of contex to interpret information code
 

Suppose we are also given the context to interpret the data:

  • You are given the the sex and marital status information on 2 persons:

         Name   MaritalStatus   Sex 
         -------------------------------
          A           1           0
          B           0           1              
      

    Can you tell the sex and marital status information of person A ???

 

 

The importance of contex to interpret information code
 

We can now interpret the code:

  • You are given the the sex and marital status information on 2 persons:

         Name   MaritalStatus   Sex 
         -------------------------------
          A           1           0
          B           0           1              
      

    Can you tell the sex and marital status information of person A ???

 

Person A is married (1) and a male (0) !!!

Application:   how do computer programs use the context information ?

  • Recall:   code + context = information

  • A (program) variable has:

    • A value (which is stored as a binary number)

              I.e.:   value = code

    • A data type that tells the computer how to interpret (=decode) the value

              I.e.:   data type = context

  • In fact:

      • A programming language provides many (different) data types

        • Each data type has its own way to encode/decode the information !!!

Application:   how do computer programs use the context information ?
 

A Java program that shows that the data type contains the context to interpret the code 65:

public class Context
{
   public static void main(String[] args)
   {
      int  x;       // The code represents a number
      char y;       // The code represents a character

      x = 65;
      System.out.println(x); // Prints "65" (read it "directly" as a number)

      y = 65;
      System.out.println(y); // Prints "A" (ASCII code 65 is 'A'
   }
}  

(The Java compiler will call a different println( ) method based on the data type of the input parameter)
See: click here

DEMO: /home/cs255001/demo/data-type/Context.java

ASCII code table: https://www.ascii-code.com/

How context can change the meaning... an English language example
 

Question:

  • Make a syntactically correct English sentence that begins with:            

           You is ....                
      

How context can change the meaning... an English language example
 

Question:

  • Make a syntactically correct English sentence that begins with:            

           You is an English word                
      

 

 

The word You is normally used in the context of a personal pronounce

The solution is to use the word You in the context of a noun !!