Bitwise Operations In Pl/Sql What Is The Assignment Operator

Summary: in this tutorial, you will learn how to use C operators including arithmetic, assignment, relational, bit-wise, increment, logical and ternary operators.

C supports many operators to perform various kinds of operations. With C operators, you can do arithmetic operations, comparing data, modifying variables, combining relationship logically, etc.

C operators operates on one or more operands to produce a value.

  • The operators that take one operand are called unary operators.
  • The operators that require two operands are called binary operators.
  • The operator that accepts three operands is called ternary operator. C  has only one ternary operator.

C Arithmetic Operators

C supports almost common arithmetic operators such as +,-,*, / and modulus operator %. The modulus operator (%) returns the remainder of integer division calculation. Note that the modulus operator cannot be applied to a double or float.

C Arithmetic Operators Precedence

The C arithmetic operators have precedence rules that are similar to the rules in math. The + and – operators have the same precedence. The precedence of *, / and % operators are higher than the + and – operators. The C arithmetic operators associate from left to right.

The following program demonstrates the C arithmetic operators:

Below is the output of the demo program:

C Assignment Operators

C assignment operators are used to assign the value of a variable or expression to another variable. The syntax of assignment operators is as follows:

Besides the assignment operator, C also supports another short hand format that works the same assignment operator with an additional operator such as +=, -=, *=, /=, %=.

Each assignment operator has a priority. And they are evaluated from right to left based on its priority. The following is the assignment operator and its priority: =, +=, -=, *=, /=, %=.

A simple C program that demonstrates assignment operators:

Here is the output:

C Bitwise Operators

C provides six bitwise operators for manipulating bit. The bitwise operator can only be applied to integral operands such as char, short, int and long. The following table illustrates C bitwise operators:

C Bitwise OperatorsDescription
&Bitwise AND
|Bitwise inclusive OR
^Bitwise exclusive OR
<<Bitwise left shift
>>Bitwise right shift
~one’s complement

The bitwise operators are preferred in some contexts because bitwise operations are faster than (+) and (-) operations and significantly faster than (*) and (/) operations.

Example of C bitwise Operators

Here is a simple program that demonstrates C bitwise operators:

And here is the output:

C Increment Operator

C provides two operators for incrementing and decrementing the value of variables.

  • The increment operator ++ adds 1 to its operand.
  • The decrement operator — subtracts 1 from its operand

The C increment and decrement operators can be used either as prefix operator or postfix operators as follows:

The C increment operator in both prefix or postfix contexts is to add 1 to a variable. But the expression ++variable increments variable before its value is used, whereas variable++ increments variable after its value has been used.

Example of C Increment Operator

Let’s take a look at a simple example that demonstrates prefix and postfix of C increment operators.

Note that in both cases x is 11 however y is 11 in the first case and 19 in the second case.

So in the case that the variable value is not used, there is no difference between prefix or postfix of the increment operator.

C Logical Operators

You use C logical operators to connect expressions and/or variables to form compound conditions. The C logical expression returns an integer (int). The result has value 1 if the expression is evaluated to true otherwise it returns 0. C uses the following symbols for the Boolean operations AND, OR, and NOT.

OperatorMeaning
&&logical AND
||logical OR
!logical NOT
The AND operator (&&) and OR operator (||) has the essential peculiarity:
  • The || operator, their operands are evaluated in order from left to right, and if the value of the left operand is sufficient to determine the result of the operation, then the right operand is not evaluated at all.
  • The operator evaluates the right operand only if the left operand yields 1;

The following table illustrates the truth table of the logical operators:

aba&&ba||b!a
TrueTrueTrueTrueFalse
TrueFalseFalseTrueFalse
FalseTrueFalseTrueTrue
FalseFalseFalseFalseTrue

Example of C Logical Operators

The following program illustrates the C logical operators:

Below is the output of the C logical operators demo program:

C Relational Operators

C provides you a list of relational operators to allows you to compare data. The relational operators enable you to check whether two variables or expressions are equal, not equal, which one is greater or less than other…etc. The relational operators are used in Boolean conditions or expressions to return 0 or 1.The following table illustrates the relational operators in C:

Relational OperatorsDescription
==Equal to
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to
!=Not equal to

C relational operators example

The following program demonstrates the relational operators in C:

Here is the output of the demo program:

* File:    main.c
* Author:  zentut.com
* Purpose: Demonstrates the C arithmetic operators
    intx=10,y=20;
    printf("x = %d\n",x);
    printf("y = %d\n",y);
    /* demonstrate = operator + */
    y=y+x;
    printf("y = y + x; y = %d\n",y);
    /* demonstrate - operator */
    y=y-2;
    printf("y = y - 2; y = %d\n",y);
    /* demonstrate * operator */
    y=y*5;
    printf("y = y * 5; y = %d\n",y);
    /* demonstrate / operator */
    y=y/5;
    printf("y = y / 5; y = %d\n",y);
    /* demonstrate modulus operator % */
    intremainder=0;
    remainder=y%3;
    printf("remainder = y %% 3; remainder = %d\n",remainder);
    return0;
remainder=y%3;remainder=1
/* a program demonstrates C assignment operator */
    intx=10;
    /* demonstrate = operator */
    inty=x;
    printf("y = %d\n",y);
    /* demonstrate += operator */
    y+=10;
    printf("y += 10;y = %d\n",y);
    /* demonstrate -= operator */
    y-=5;
    printf("y -=5;y = %d\n",y);
    /* demonstrate *= operator */
    y*=4;
    printf("y *=4;y = %d\n",y);
    /* demonstrate /= operator */
    y/=2;
    printf("y /=2;y = %d\n",y);
* File:    main.c
* Author:  http://www.zentut.com
* Purpose: Demonstrates C bitwise operators
    intd1=4,/* binary 100 */
        d2=6,/* binary 110 */
        d3;
    printf("\nd1=%d",d1);
    printf("\nd2=%d",d2);
    d3=d1&d2;
    printf("\n Bitwise AND  d1 & d2 = %d",d3);
    d3=d1|d2;
    printf("\n Bitwise OR d1 | d2 = %d",d3);
    d3=d1^d2;
    printf("\n Bitwise XOR d1 ^ d2 = %d",d3);
    d3=~d1;
    printf("\n Ones complement of d1 = %d",d3);
    d3=d1<<2;
    printf("\n Left shift by 2 bits d1 << 2 = %d",d3);
    d3=d1>>2;
    printf("\n Right shift by 2 bits d1 >> 2 = %d",d3);
BitwiseAND  d1&d2=4
Onescomplementofd1=-5
Leftshiftby2bitsd1<<2=16
Rightshiftby2bitsd1>>2=1
* File:    main.c
* Author:  zentut.com
* Purpose: Demonstrates C increment operator
    intx=10;
    inty;
    /* prefix */
    y=++x;
    printf("x = %d\n",x);
    printf("y = %d\n",y);
    x=10;
    /* postfix */
    y=x++;
    printf("x = %d\n",x);
    printf("y = %d\n",y);
    return0;
* File:    main.c
* Author:  zentut.com
* Purpose: A program demonstrates C logical operators
#include <stdlib.h>
intmain(intargc,char**argv){
    intx=10;
    inty=15;
    intz=20;
    if(x<y&&y<z){
        printf("x > y && y < z\n");
    }
    if(x>y||y<z){
        printf("x > y || y < z\n");
    }
    if(!(x>y)){
        printf("!(x > y)\n");
    }
    return(0);
x>y&&y<z
* File:    main.c
* Author:  zentut.com
* Purpose: A program demonstrates C relational operators
#include <stdlib.h>
* Relational operators demo
voiddemo(intx,inty){
    printf("x = %d;y = %d\n",x,y);
    if(x==y){
        printf("x is equal to y\n");
    }elseif(x!=y){
        printf("x is not equal to y\n");
        if(x>y){
            printf("x is greater than y\n");
        }else{
            printf("x is less than y\n");
        }
    }
*  main program
intmain(intargc,char**argv){
    intx=10;
    inty=10;
    demo(x,y);
    x=10;
    y=20;
    demo(x,y);
    x=20;
    y=10;
    demo(x,y);
    return(0);

& (Bitwise AND) (Transact-SQL)

Performs a bitwise logical AND operation between two integer values.

Transact-SQL Syntax Conventions

Syntax

Arguments

expression
Is any valid expression of any of the data types of the integer data type category, or the bit, or the binary or varbinary data types. expression is treated as a binary number for the bitwise operation.

Note

In a bitwise operation, only one expression can be of either binary or varbinary data type.

Result Types

int if the input values are int.

smallint if the input values are smallint.

tinyint if the input values are tinyint or bit.

The & bitwise operator performs a bitwise logical AND between the two expressions, taking each corresponding bit for both expressions. The bits in the result are set to 1 if and only if both bits (for the current bit being resolved) in the input expressions have a value of 1; otherwise, the bit in the result is set to 0.

If the left and right expressions have different integer data types (for example, the left expression is smallint and the right expression is int), the argument of the smaller data type is converted to the larger data type. In this case, the smallintexpression is converted to an int.

Examples

The following example creates a table using the int data type to store the values and inserts two values into one row.

This query performs the bitwise AND between the and columns.

Here is the result set:

The binary representation of 170 ( or ) is . The binary representation of 75 ( or ) is . Performing the bitwise AND operation on these two values produces the binary result , which is decimal 10.

See Also

Expressions (Transact-SQL)
Operators (Transact-SQL)
Bitwise Operators (Transact-SQL)
&= (Bitwise AND Assignment) (Transact-SQL)
Compound Operators (Transact-SQL)

0 Replies to “Bitwise Operations In Pl/Sql What Is The Assignment Operator”

Lascia un Commento

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *