Bit Operators (& and, | or, ^ Xor)
|
a.cmain(){printf("%d\n",4 & 5);} Output4 |
8
4 2 1
= 4 8
4 2 1
= 5 --------------------- 8
4 2 1
= 4 |
||||||||||||||||||||||||||||||||||||||
a.cmain(){printf("%d\n", 4 | 2);} Output6 |
8
4 2 1
= 4 8
4 2 1
= 2 --------------------- 8
4 2 1
= 6 |
||||||||||||||||||||||||||||||||||||||
a.cmain(){printf("%d\n",4^2);printf("%d\n",4^6);printf("%d\n",2^6);} Output624 |
8
4 2 1
= 4 8
4 2 1
= 2 --------------------- 8
4 2 1
= 6 |
8
4 2 1
= 4 8
4 2 1
= 6 --------------------- 8
4 2 1
= 2 |
8
4 2 1
= 2 8
4 2 1
= 6 --------------------- 8
4 2 1
= 4 |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
encrypt-decrypt.c // Usage: encrypt-decrypt <sorc.file> <dest.file> <password> #include<stdio.h>main(int argc, char *argv[]) {FILE *fpi,*fpo; char *p; int i;p=argv[3];fpi=fopen(argv[1],"rb");fpo=fopen(argv[2],"wb"); while((i=fgetc(fpi))!=-1) { i=i^*p; p++; if(*p==0) p=argv[3]; fputc(i,fpo); }}
C:\> encrypt-decrypt Orignal.doc Encrypt.doc password C:\> encrypt-decrypt Encrypt.doc Orignal.doc passwordBack to the main page