सोलर योजना,अब ग्रामीणों को मिलेगी बिजली के बिल से राहत

भारत सरकार द्वारा ग्रामीण इलाकों में सौर ऊर्जा के विस्तार तथा ग्रामीणों को सरलता से बिजली उपलब्ध कराने के उद्देश्य से  योजनाएं लागू की गई है, इस प्रकार की योजनाओं से ग्रामीणों को बिजली के बिल से भी राहत मिल सकेगी  भारत सरकार ग्रामीण क्षेत्रों में सौर ऊर्जा को बढ़ावा देने के लिए विभिन्न योजनाएं चला रही है, जिनमें से प्रमुख हैं: 1. पीएम सूर्य घर योजना:- सरकार द्वारा परंपरागत ऊर्जा स्रोतों के अलांवा अब वैकल्पिक ऊर्जा स्रोतों को बढ़ाने और ग्रामीणों को हर महीने बिजली के बल से राहत प्रदान करने के उद्देश्य से पीएम सूर्य घर योजना लागू की गई है इस योजना के तहत, सरकार घरेलू छतों पर सोलर पैनल लगाने के लिए 60 फीसदी तक की सब्सिडी प्रदान करती है। पीएम सूर्य घर योजना क्या है? प्रधानमंत्री सूर्य घर मुफ्त बिजली योजना भारत सरकार द्वारा शुरू की गई एक योजना है, जिसके तहत घरों की छतों पर सोलर पैनल लगाने के लिए सब्सिडी दी जाती है। इस योजना का उद्देश्य लोगों को फ्री में 300 यूनिट तक बिजली उपलब्ध कराना और बिजली बिल को कम करना है। योजना के लाभ: ✔ 300 यूनिट तक मुफ्त बिजली ✔ सोलर पैनल लगाने पर 60% ...

Bitwise Operators in C Programming | All you need to know about Operation on BITS

Inside the computer, the data is represented in Binary digits called Bits ( 0 & 1). System-level programming requires the manipulation of individual bits within a byte. This feature in C is implemented through bitwise operators.

The different types of bitwise operators are:

OPERATORS                            OPERATIONS


  &                                       Bitwise AND

|                                           Bitwise OR

^                                Bitwise XOR (Exclusive OR)

~                               Bitwise NOT (One’s Complement)

<<                                 Bitwise Left Shift


>>                                Bitwise Right Shift



All the operators here are binary except the complement operator, which is unary. The bitwise operators work on data of integral type only i.e. char, int, short, long including signed and unsigned. It is always better to use unsigned integer types while doing bit manipulation.

The operands for bitwise operators can be constants or variables. While using these operators, we will consider the binary representation (bit pattern) of the operand. A bit is ON (or set) if its value is 1, while it is OFF (or clear ) if its value is 0. All bitwise operators except complement operator can be combined with the assignment operator to form the compound assignment operator i.e.

&=,                    |=,                  <<=,               >>=,             ^= 




What are LOGICAL BITWISE OPERATORS ( &, |, ^, ~)?

Bitwise AND, Bitwise OR, Bitwise XOR are binary operators and require two operands. These operands are compared bitwise i.e. all corresponding bits in both operands are compared.


For AND (&):

Bit of Operand 1        Bit of Operand 2        Resulting Bit

0                                0                                0

0                                1                                0

1                                0                                0

1                                1                                1

For OR ( | ):

Bit of Operand 1        Bit of Operand 2        Resulting Bit

0                                0                                0

0                                1                                1

1                                0                                1

1                                1                                1

For XOR ( ^ ):

Bit of Operand 1        Bit of Operand 2        Resulting Bit

0                                0                                0

0                                1                                1

1                                0                                1

1                                1                                0


For NOT ( ~ ):

Bit of Operand         Resulting Bit

0                                1

1                                0


How Bitwise Operator Works?


When bitwise operators ( &, |, ^ ) operate on two operands of different sizes, the size of the smaller operand is increased to match the size of the larger operand. For example, if there are two operands of sizes 16 and 32 bits then the 16-bit operand will be converted to 32 bits. The extra bits are added to the left of the smaller operand. If the smaller operand is unsigned then all these extra bits are filled with zeros, and if it is signed then these bits are filled with sign bits.

When a complement operator is applied to an operand twice, the result is the original operand i.e. ~(~a) is equal to a. This feature of the complement operator can be used for encrypting and decrypting the data. The order of precedence of these operators from highest to lowest is a bitwise complement, bitwise AND, bitwise XOR, bitwise OR. The complement operator associates from right to left and the other three from left to right.

The == and! = have higher precedence than three binary bitwise operators, so parentheses are needed if we want the bitwise operation to take place before the comparison.


What are SHIFT OPERATORS?

There are two types of bitwise shift operators:

  • Bitwise left shift (<<): Used for shifting the bits left.

  • Bitwise right shift (>>): Used for shifting the bits right.

Both require two operands, in Bitwise left shift the left operand is the operand whose bits are shifted and the right operand indicates the number of bits to be shifted. On shifting the bits left, an equal number of bit positions on the right are vacated. These positions are filled with 0 bits.

Example: X = 0xD57F1347 and find X<<4. 

The binary equivalent of 0xD57F1347 will be 11010101 01111111 00010011 01000111, when this number is left-shifted by 4, the new number will be 01010111 11110001 00110100 01110000. This shows that the leftmost 4 bits are lost and the rightmost 4-bit positions are filled with 0 bits.

Bitwise right shift operator (>>) shifts the bits to the right side. If we shift the bits right, an equal number of bit positions on the left will be vacated. These positions are filled in with 0 bits in unsigned integers.

Example: X = 0xD57F1347 and find X>>4.

The binary equivalent of 0xD57F1347will be 11010101 01111111 00010011 01000111, when this number is right-shifted by 4, the new number will be 00001101 01010111 11110001 00110100. This shows that the leftmost 4 bits are lost and the rightmost 4-bit positions are filled with 0 bits.

In the right shift the first operand (operand to be shifted) is signed integer (negative integer), some machines perform logical shift (vacated bit positions are filled with 0’s) while other machines perform arithmetic shift (vacated bit positions are filled with sign bit). The sign bit is the leftmost bit (high-order bit) and is 1 for negative integers and 0 for non-negative integers. Thus to avoid non-portable code, we should use unsigned integers while right shifting.

While using left shift and right shift operators, the result is undefined if the right operand is negative or it is more than or equal to a number of bits used to represent the left operand.


How to do multiplication and division by 2 using shift operators?

  • Shifting one bit right is equivalent to integer division by 2.
  • Shifting one bit left is equivalent to multiplication by 2.
After knowing this we can use these operators to divide and multiply integers by the power of 2.

For example: To multiply an integer by 2^2, we will shift it left by two bits, to multiply by 2^3 we will shift it left by 3 bits. Similarly to divide an integer by 2^2, we will right shift it by 2 bits, to divide by 2^3 we will right shift it by 3 bits. 


What is Masking?

Masking is an operation in which we can selectively mask or filter the bits of a variable, such that some bits are changed according to our needs, while others remain unchanged. With the help of masking, we can change bits into a bit pattern and perform various operations such as switching ON or OFF, inverting, or testing a bit.

Masking is performed with the help of Bitwise operators. The pattern of bit to be masked is taken as the first operand and the second operand is called MASK.

The mask is selected according to our requirements.

Masking using Bitwise AND

Example- 10101111 00011111 (Value of x)

                   00000000 11111111 (Mask)

                   00000000 00011111  (New value)

Here we can see that whenever there is 0 in the mask, the new bit value becomes 0 while the new bit value remains unchanged when there is 1 in the mask.

We can clear any bit using & operator. For example, if we want to clear the last 4 bits in a bit pattern, we can choose a mask such that the last four bits are 0, all other bits are 1.

Example-            10101111 00011111 (Value of x)

                            11111111 11110000 (Mask)

                            10101111 00010000  (New value)

We can use either of these two statements to switch off the last 4 bits in an integer.

X= X & 0xFFF0;

X= X & ~0xF;

In the first statement, the mask is oxFFF0 and in the second the mask is ~0xF. The second form is portable as it is independent of the word length of the machine. The second form makes the code portable.

Bitwise AND operator can be used to test whether a particular bit is set or clear. Suppose if we want to test the 5th bit, we will select a mask with only the 5th-bit set, the rest of the bits will be 0. If the 5th bit in the bit pattern of x is 0, then the new value will be zero, and if the 5th bit in the original bit pattern is 1, then the new value will be non-zero (32).

Masking using Bitwise OR

We use bitwise OR to set particular OR bits. The mask is chosen in such a way that the bits to be set are 1 and the rest of the bits are 0. Whenever there is 1 in a mask, the new bit value becomes 1 while the new bit value remains unchanged when there is 0 in the mask. 

X = X | Mask.


Example-            10101111 00000000 (Value of x)

                             11111111 11110000 (Mask)

                             11111111 11100000(New value)


Masking using Bitwise XOR

When there is 1 in the mask, the corresponding bit value is inverted while the new bit value remains unchanged when there is a 0 in the mask. The complement operator complements all the bits in a number, but if we want to complement some particular bits in a number, we can use bitwise XOR. The mask should be chosen such that the bits to be complemented should be 1, rest of the bits should be zero.

X = X ^ Mask;

Thus bitwise XOR can be used to toggle the bits between 0 and 1.

For example, If we have integer variable X, and we want to toggle the 5th bit, suppose initially the 5th bit in variable x is 1.

a = a ^ mask; (5th-bit changes to 0, all other bits unchanged)

a = a ^ mask; (5th-bit changes to 1, all other bits unchanged)

a = a ^ mask; (5th-bit changes to 0, all other bits unchanged)

When an operand is XORed twice, we get the original operand. This feature can be used for encryption.

var = var ^ 0x1F; (Encryption)

var = var ^ 0x1F;(Decryption)

When the value is XORed with itself we get 0.

We can calculate MASK for a particular bit position by left shifting integer 1 by the position of bit.

MASK = 1 << BITPOSITION;

Example:

For manipulating 4th bit: mask = 1 << 4,

For manipulating 6th bit: mask = 1 << 6.

-Shikha Mishra

Comments

Popular posts from this blog

Most trending cafe and restaurant chain Btechchaiwala

BtechChaiwala explains how to run your restaurant

Btechchaiwala | Boost your restaurants sell using technology | How technology can improve your business