marq

Dr. Charles Simonyi is the Father of Modern Microsoft Excel                                           JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript.                                           The word "Biology" is firstly used by Lamarck and Treviranus                                           Hippocrates (460-370 bc) is known as father of medicine.                                           Galene, 130-200 is known as father of Experimental Physology                                           Aristotle (384-322 BC) is known as Father of Zoology because he wrote the construction and behavior of different animals in his book "Historia animalium"                                           Theophrastus(370-285 BC) is known as father of Botany because he wrote about 500 different plants in his book "Historia Plantarum".                                           John Resig is known as Father of Jquery -                                          HTML is a markup language which is use to design web pages. It was invented in 1990 by Tim Berners-Lee.                                                                The Google was founded by Larry Page and Sergey Brin.                                                                Rasmus Lerdorf was the original creator of PHP. It was first released in 1995.                                                               Facebook was founded by Mark Zuckerberg                                                               Bjarne Stroustrup, creator of C++.                                                                Dennis Ritchie creator of C                                                                                                                              James Gosling, also known as the "Father of Java"                                          At 11.44%, Bihar is India's fastest growing state                                          Father of HTML -Tim Berners Lee                                          orkut was created by Orkut Büyükkökten, a Turkish software engineer                    Photoshop: It came about after Thomas Knoll, a PhD student at the University of Michigan created a program to display grayscale images on a monochrome monitor which at the time was called 'Display'.

Bitwise Operators - C in Hindi


Bitwise AND Operator ( & )
ये Operator Use करके हम दो Identifier के Bits पर AND Masking की प्रक्रिया को Apply करते हैं। AND Masking में दोनों Identifiers के Bits आपस में AND Form में Compare होते हैं। यदि दोनों Identifiers में समान Position पर Bit का मान 1 हो यानी Bit True हो तो Resultant Bit भी True होता है, अन्यथा Resultant Bit False हो जाता है। उदाहरण के लिए 19 की Binary 10011 होती है और 21 की Binary 10101 होती है। अब यदि निम्नानुसार दो Variables में ये दोनों मान Stored हों:



और यदि इन दोनों Identifiers पर निम्नानुसार AND Masking करके Resultant मान को result नाम के Variable में Store किया जाए, तो Result निम्नानुसार प्राप्त होगा :




AND Masking में निम्नानुसार Table के अनुसार Bits पर प्रक्रिया होती है, जिसमें यदि दोनों Identifiers के समान Position के दोनों Bits का Comparison होता है और समान Position पर ही Resultant Bit Return होता है।




इस Bitwise Operator का प्रयोग अक्सर ये जानने के लिये किया जाता है, कि किसी Operand का कोई अमुक Bit ON ( 1 ) है या OFF ( 0 ) किसी Operand का कोई Bit On है या Off, ये जानने के लिये हमें एक अन्य Operand लेना होता है और उस Operand में उस Bit को On रखा जाता है, जिसे प्रथम Operand में Check करना होता है।

उदाहरण के लिए माना एक Operand का Bit Pattern 11000111 है और हम जानना चाहते हैं कि इस Pattern में चौथा Bit ON है या नहीं। ये जानने के लिये हमें एक दूसरा Operand लेना होगा और उस Operand के Bit Pattern में चौथे Bit को ON(1) व द्रोष Bits को OFF(0) रखना होगा। इस प्रकार से हमें दूसरे Operand का जो Bit Pattern प्राप्त होगा वह 00001000 होगा, जिसका चौथा Bit ON है।

किसी Operand के Bit Pattern के किसी Bit की स्थिति पता करने के लिये दूसरा Bit Pattern लेकर जो प्रक्रिया की जाती है, उसे Masking कहते हैं और जब इस प्रक्रिया में Bitwise Operator & का प्रयोग किया जाता है, तब इसे AND Mask कहते हैं।

Trick ये है कि जब हम प्रथम Operand को & Operator द्वारा दूसरे Operand के Bit Pattern से Compare करते हैं तब यदि प्रथम Bit Pattern में चौथा Bit ON होता है, तो ही Comparison से प्राप्त Resultant Bit Pattern में भी चौथा Bit ON होता है अन्यथा चौथा Bit Off होता है। इस Masking को हम निम्नानुसार Represent कर सकते हैं:



इस उदाहरण में हम देख सकते हैं कि पहले Bit-Pattern का चौथा Bit Off है, इसलिए Resultant Bit-Pattern में भी चौथा Bit Off है। अब निम्न Fragments को देखिएः



इस Fragment में हम देख सकते हैं कि पहले Bit-Pattern का चौथा Bit On है और यही जानने के लिए कि पहले Operand का चौथा Bit On है या नहीं, हमने एक Mask Bit Pattern Create किया है, जिसके चौथे Bit को On रखा है। इस स्थिति में Resultant Bit-Pattern का चौथा Bit केवल उसी स्थिति में On हो सकता है, जब Check किए जा रहे Operand के Bit-Pattern में चौथा Bit On हो। इस तरह से AND Masking के उपयोग द्वारा हमें पहले Operand के चौथे Bit की स्थिति का पता चल जाता है।

किसी भी Bit-Pattern में हर Bit की Position का एक मान होता है। इस Position के मान द्वारा हम Directly उस Bit को Refer कर सकते हैं। उदाहरण के लिए निम्न चित्र को देखिएः


 
इस चित्र में हर Bit Position के साथ एक Number Associated है। यदि हम किसी Bit-Pattern के चौथे Bit को Refer करना चाहते हैं, तो हमें मान 16 को Use करना होता है। इसी तरह से यदि हमें किसी Bit Pattern के छठे Bit को Access करना हो, तो हमें इस Bit Position से Associated मान 64 को Use करना होता है।

चलिए, अब हम एक उदाहरण द्वारा Logical AND Operator को Use करके किसी Identifier के किसी Particular Bit की Status को Check करते हैं कि वह Bit On है या नहीं। इस उदाहरण में हमने एक Identifier x में एक मान 150 Store किया है, जिसका Bit-Pattern 1001011 होता है। हम इस Bit-Pattern के पांचवे व छठे Position के Bit की ON/OFF Status जानना चाहते हैं। चूंकि हम किसी भी मान के Bit-Pattern को Binary Form में Use नहीं कर सकते हैं, इसलिए किसी Bit Position को Refer करने के लिए हमें उसके साथ Associated Decimal Number को Use करना होता है।


Program
view plainprint?
#include <stdio.h>
#include <conio.h>
 
main()
{
int x = 150; // Bit-Pattern of 150 = 10010110
int j;
clrscr();
 
printf(“\n Value of x is %d “, x);
 
j = x & 16;
(j == 0) ? printf(“\n Fifth Bit of value %d is Off”, x) :  
printf(“\n Fifth Bit of value %d is On”, x);  
 
j = x & 32;
(j == 0) ? printf(“\n Sixth Bit of value %d is Off”, x) :  
printf(“\n Sixth Bit of value %d is On”, x);  
 
getch();
}  

Output
Value of x is 150
Fifth Bit of value 150 is On
Sixth Bit of value 150 is Off

जब ये Program Run होता है, तब निम्नानुसार Form में j = x & 16; व j = x & 32; Statements को Execute करता हैः



चूंकि जब हम पांचवे Bit को Check करते हैं, तब मान 150 का पांचवा Bit On होने की वजह से Making Process से 1 Generate होता है और ये 1 Variable j में Store हो जाता है। फिर Ternary Operator में (j==0) Expression Execute होता है, जो कि False हो जाता है, क्योंकि j का मान 1 है और (1==0) नहीं होता है। इस वजह से Ternary Operator के दूसरे Statement का Execution हो जाता है, जो Output में निम्नानुसार Message प्रदान करता हैः

Fifth Bit of value 150 is On

लेकिन जब हम छटे Bit को Check करते हैं, तब मान 150 का छठा Bit Off होने की वजह से Masking Process से 0 Generate होता है और ये 0 Variable j में Store हो जाता है। अगले Statement में फिर से (j==0) Expression Execute होता है, जो इस बार True होने की वजह से Ternary Statement के पहले Statement का Execution कर देता है और हमें निम्नानुसार Output प्राप्त होता हैः

Sixth Bit of value 150 is Off

इस प्रकार से हम किसी भी Identifier के मान के किसी Particular Bit को On/Off Status की जानकारी प्राप्त करने के लिए Bitwise AND Operator का प्रयोग कर सकते हैं। सामान्यतया विभिन्न प्रकार के Bitwise Operators का प्रयोग विभिन्न प्रकार के Hardware Devices के साथ प्रक्रिया करने के लिए ही करते हैं।

Bitwise OR Operator ( | )
ये Operator Use करके हम दो Identifier के Bits पर OR Masking की प्रक्रिया को Apply करते हैं। OR Masking में दोनों Identifiers के Bits आपस में OR Form में Compare होते हैं। यदि दोनों Identifiers में से किसी एक भी Identifier में समान Position पर Bit का मान 1 हो यानी Bit True हो तो Resultant Bit भी True होता है, अन्यथा Resultant Bit False हो जाता है। OR Masking को हम निम्नानुसार समझ सकते हैं, जहां दो Variables में 19 व 21 मान Stored हैः



इन दोनों Identifiers पर OR Masking की प्रक्रिया को Apply करने पर निम्नानुसार Operation Perform होते हैं:



OR Masking में Identifier के Bits पर निम्नानुसार Table के अनुसार पर प्रक्रिया होती है, जिसमें दोनों Identifiers के समान Position के दोनों Bits का आपस में Comparison होता है और तीसरे Identifier में समान Position पर ही Resultant Bit Return होता है।



Bitwise OR Operator का प्रयोग किसी Bit Pattern में स्थित किसी खास Bit को ON करने के लिये किया जाता है। जब हमें किसी अमुक Bit को किसी Bit-Pattern में ON करना होता है, तब हमें एक और Bit-Pattern की जरूरत होती है। इस दूसरे Bit-Pattern को OR Mask Bit Pattern कहते हैं। इस OR Mask में हमें केवल उसी Bit का मान 1 रखना होता है, जिसे हम हमारे प्रथम Bit-Pattern में ON करना चाहते हैं।

चलिए, एक उदाहरण द्वारा OR Masking की प्रक्रिया को समझते हैं। मानलो कि हम Bit-Pattern 10100110 (Value = 150) की चौथी Bit को On करना चाहते हैं। इस जरूरत को पूरा करने के लिए हमें OR Mask के रूप में Bit-Pattern 00001000 को Use करना होगा। जब हम इस पर OR Masking की प्रक्रिया करनी हो, तो ये प्रक्रिया निम्नानुसार होगीः




Resultant मान में हम देख सकते हैं, कि इसके केवल चौथे Bit का मान ही 0 स 1 हुआ है। चूंकि चौथे Bit-Position का मान 8 होता है, इसलिए Resultant मान 158 प्राप्त हो रहा है, जो कि Original मान 150 से केवल 8 ही ज्यादा है। इस समस्या का Program निम्नानुसार हैः


Program
view plainprint?
#include <stdio.h>
#include <conio.h>
main()
{
int x = 150, j;
clrscr();
printf("\n Value of x is %d ", x);
 
j = x | 8;
printf("\n Forth Bit of value %d is Now On", x);
printf("\n Now the Value of x is %d " , j);
 
getch();
}

Output:
Value of x is 150
Forth Bit of value 150 is Now On
Now the Value of x is 158


Bitwise XOR (Exclusive OR) Operator ( | )
ये Operator Use करके हम दो Identifier के Bits पर XOR Masking की प्रक्रिया को Apply करते हैं। XOR Masking में दोनों Identifiers के Bits आपस में XOR Form में Compare होते हैं। यदि दोनों Identifiers में से किसी एक भी Identifier में समान Position पर Bit का मान 1 हो यानी Bit True हो तो Resultant Bit भी True होता है, लेकिन यदि दोनों ही Identifiers में समान Position पर समान Bit हो, तो Resultant Bit False हो जाता है। XOR Masking को समझने के लिए हम पिछले उदाहरण को ही Use कर रहे हैं, जिसमें दो Variables में मान 19 व 21 Stored हैं:



इन दोनों Identifiers पर XOR Masking की प्रक्रिया को Apply करने पर निम्नानुसार Operation Perform होते हैं:




XOR Masking में निम्नानुसार Table के अनुसार Bits पर प्रक्रिया होती है, जिसमें दोनों Identifiers के समान Position के दोनों Bits का आपस में Comparison होता है और समान Position पर ही Resultant Bit Return होता है।



इस Operator का प्रयोग करके हम किसी Identifier की Bits को Toggle तरीके से बार-बार On/Off कर सकते हैं। यानी जब हमें किसी Identifier के Bits को Toggle तरीके से On/Off करना होता है, तब हम इस Bitwise Operator का प्रयोग करते हैं। इस Operator को हम निम्न Program के अनुसार Use कर सकते हैं:

Program:
view plainprint?
#include <stdio.h>
#include <conio.h>
 
main()
{
int x = 50, k=10;
clrscr();
printf("\n Value of x is %d ", x);
printf("\n\n Value of k is %d ", k);
 
printf("\n\n k = %d is Masking the value of x = %d \n", k, x);
x = x ^ k;
printf("\n After XOR Masking the Value of x is %d \n" , x);
 
printf("\n k = %d is Masking the Changed Value of x = %d again", k, x);
x = x ^ k;
printf("\n\n Now the Value of x is changed again to %d " , x);
 
getch();
}

Output:
Value of x is 50                             // Bit-Pattern : 00110010
Value of k is 10                             // Bit-Pattern : 00001010
k = 10 is Masking the value of x = 50  
After XOR Masking the Value of x is 56       // Resultant : 00111000
k = 10 is Masking the Changed Value of x = 56 again
Now the Value of x is changed again to 50    // Resultant : 00110010


One’s Complement Bitwise Operator ( ~ )
इस Operator का प्रयोग करके हम किसी भी Identifier के मान की Bits को Invert कर सकते हैं। जब किसी मान की Bits को Invert कर दिया जाता है, तब Generate होने वाले मान का चिन्ह बदल जाता है। इस प्रक्रिया को हम निम्नानुसार समझ सकते हैं:



One’s Complement को समझने के लिए हम निम्नानुसार एक Program बना सकते हैं:

Program:
view plainprint?
#include <stdio.h>
#include <conio.h>
 
main()
{
int j = 150, k;
clrscr();
k = ~j;
printf("\n Original Value is = %d", j);
printf("\n Complemented Value is = %d", k);
getch();
}

Output:
Original Value is     = 150
Complemented Value is = -151


Right Shift Operator  ( >> )
ये Operator, Operand के Bits को Right में Shift करने का काम करता है। हमें किसी Operand के Bits को जितना Shift करना होता है, हम इस Operator के बाद वह संख्‍या लिख देते हैं। जैसे val का मान 128 है और हमें इसके Bits orientation को 2 अंक Right में Shift करना हो तो हम val >> 2 लिखते हैं। इस Statement से val में Stored Bits 10000000 दो Bit Right में Shift हो जाता है और हमें 00100000 प्राप्त होता है। हम जितने Bits Right में Shift करते हैं, Bit-Pattern में Left side में उतने ही 0 fill हो जाते हैं। इसे एक उदाहरण द्वारा देखते हैं।

Program
view plainprint?
#include <stdio.h>
#include <conio.h>
 
main()
{
int k = 1028, l;
clrscr();
 
printf("\n Value of Identifier K is %d \n", k);
l = k >> 2;
printf("\n After 2-Bits Right Shifting \n");
printf(" The Value of K is %d \n", l);
 
getch();
}

Output
Value of Identifier K is 1028
After 2-Bits Right Shifting
The Value of K is 257

इस प्रोग्राम में हम देख सकते हैं कि Operand k में Stored Bits, Right में Shift हो रहे हैं। जैसे-जैसे Bits Right में Shift होते हैं तो k का मान भी बदलता जाता है। Right Shifting से एक और बहुत महत्वपूर्ण तथ्य सामने आता है, जो ये है कि यदि हम क्रम से किसी संख्‍या को एक-एक Bit Right Shift करते जाते हैं, तो Operand का मान भी क्रम से आधा होता जाता है। यानी Right Shifting से हम जितने Bits Right में Shift करते हैं, उतनी ही बार Operand का मान आधा हो जाता है। जैसे इस Program में हुआ है। 1028 को यदि 4 Bit Right में Shift किया जाए तो ये कहा जा सकता है कि 1028 में चार बार दो का भाग दिया गया है। यानी

1028/ 2             =          514
 514 / 2             =          257

हमने जैसा कि पहले बताया कि हम Bitwise Operators का प्रयोग केवल char या int प्रकार के Operand के साथ ही कर सकते हैं और यहां int प्रकार के Operand k के साथ प्रक्रिया की है। यहां ये सवाल दिमाग में आ सकता है कि 257 / 2 = 128.5  होना चाहिये था फिर 256 क्यों हुआ। इसकी वजह यही है कि int प्रकार का मान पूर्णांक में ही हो सकता है। int में दसमलव संख्‍याऐं मान्य नहीं हैं और Bitwise Operators float या double को मान्य नहीं करते, वे केवल int या char को मान्य करते हैं। इसलिये यहां 128.5 ना हो कर 128 ही हुआ है।


Left Shift Operator ( << )
Left Shift Operator के काम करने का तरीका बिल्कुल वही है जो Right Shift Operator का है। लेकिन दोनों के काम करने का क्रम बिल्कुल विपरीत है। ये किसी Operand के Bits को Left में Shift करता है और Right में खाली हुए स्थान को 0 से भर देता है। इसे समझने के लिये हम ऊपर के ही उदाहरण में केवल इतना बदलाव कर रहें हैं, यानी जहां पर Right Shift Operator का प्रयोग किया था, वहां पर Left Shift Operator का प्रयोग कर रहे हैं और k का मान 1028 से बदल कर 128 कर रहे हैं।

view plainprint?
#include <stdio.h>
#include <conio.h>
 
main()
{
int k = 128, l;
clrscr();
 
printf("\n Value of Identifier K is %d \n", k);
l = k << 2;
printf("\n After 2-Bits Right Shifting \n");
printf(" The Value of K is %d \n", l);
 
getch();
}  
Output
Value of Identifier K is 128
After 2-Bits Right Shifting
The Value of K is 512

जैसाकि हमने अभी बताया कि Left Shift Operator, Right Shift Operator से विपरीत Output देता है। जिस प्रकार से Right Shifting में Operand का मान आधा होता जाता है, उसी प्रकार से Left Shifting में Operand का मान पूर्व मान से दुगुना होता जाता है। यही वजह है कि मान 128 को 2 Bit Left Shift करने से उसका मान 512 हो गया है। किसी Operand के 2 Bits को Left में Shift करने का मतलब है, उस संख्‍या को दो बार दुगुना करना । इस प्रक्रिया को हम निम्नानुसार समझ सकते हैं:

128      *           2          =          256
256      *           2          =          512



Comments
“C” Language में Program लिखते समय विभिन्न प्रकार के Comments दिए जा सकते हैं। ये Comments Programmer अपनी सुविधा के लिए लिखता है। विभिन्न प्रकार के Comments द्वारा एक Programmer Program के Flow को तथा Program में Use किए जाने वाले Special Tricks को Specify करता है, जिससे Program Readable हो जाता है। सामान्यतया Comments को Program के Documentation Section में लिखा जाता है, लेकिन एक Programmer Program में किसी भी स्थान पर Comments लिख सकता है।

“C” Language Program में Comments को लिखने के लिए /* … */ का प्रयोग किया जाता है। इस Symbol के बीच लिखे जाने वाले Statements केवल Source File में ही उपयोगी होते हैं। Comments कभी भी Compile नहीं होते हैं। Compiler किसी Source File में लिखे गए विभिन्न Comments को Compilation के समय हमेंशा Ignore कर देता है, इसलिए Comments की वजह से कभी भी Executable File की Size में कोई फर्क नहीं पडता है।

हम एक Program में किसी भी स्थान पर Comment लिख सकते हैं। लेकिन किसी एक Comment के अन्दर दूसरे Comment की Nesting नहीं कर सकते हैं। जैसे

/* This is my first C Program */

ये एक सामान्य Comment है। लेकिन

/* This is my /*first*/ C Program */

ये एक गलत Comment है, क्योंकि इसमें एक Comment के अन्दर दूसरे Comment को Nest किया गया है। हम printf() या scanf() जैसे किसी Function में भी Comment को नहीं लिख सकते हैं। यदि हम ऐसा करते हैं, तो Program तो Compile होता है, लेकिन Output में वह Comment भी Print हो जाता है। जैसेः

printf("/*This is my first printf() function */ Hello");

Output:
/*This is my first printf() function */ Hello

हम देख सकते हैं कि इस Statement के Output में Comment भी Compile हो रहा है।

No comments:

Post a Comment