2. Definition
• A bit is the smallest possible unit of data
storage and has only two values: 0 and 1
• Types:
1. The one’s complement
2. The logical bitwise operator
3. The shift operators
3. 1. The one’s complement
• The one’s complement operator is
(~) is a unary operator that reverses
the bit values i.e. 0 becomes 1 and 1
becomes 0.
• Example: 1111000
0000111
4. 2. The logical bitwise operator
• Three logical bitwise operators are:
1. Bitwise and (&): returns 1 if both conditions
are true or 1 else returns 0
2. Bitwise or (|): returns 1 if any one condition
is 1 or true else returns 0.
3. Bitwise exclusive or(^): returns 1 if any one
condition is 1 or true.
6. 3. The shift operators
• The two shift operators are shift left (<<) and
shift right (>>) shift the bits in an integer
variable by the specified number of positions
say n.
• Syntax: x<<n
x>>n
Example: 0111 1100 shift a<<5
1100 0000
7.
8. Definition
• Converting one data type to another data type
is called type conversion.
• Two ways are: automatic conversion (implicit
conversion) and type casting (explicit
conversion)
• Ex: implicit float a=5.5, b=10.;
int c=a + b;
explicit float a=5.5, b=10.4;
int c= (int)a + (int)b;
10. Introduction
Data is stored in file in the secondary memory.
File specification includes:
1. Filename
2. Data structure
3. Purpose
11. 1. File pointer
• To work with files in system, a
pointer to that file is required.
• Syntax: FILE *file_pointer;
FILE *fp;
12. 2. Opening a file
• To perform any operation, file must be
opened.
• fopen() function is used which takes file name
and mode of operation.
• Syntax: fopen(file_name, mode);
• Example: FILE *fp;
fp= fopen(“temp.dat”, ”r”);
13. 3. Closing a file
• To close a file, fclose() function is
used along with file pointer.
• Syntax: fclose(file_pointer);
• Example: fclose(fp);
14. 4. fprintf and fscanf functions
• They work same way like printf and scanf
functions except that these work on files.
• Syntax: fprintf(fp, “ control string”, list);
• Example:
fprintf(f1,”%s %d ”, name, age);
fscanf(f1, “%s %d”, &name, &age);