Monday 17 December 2012

Language of the Computer:Logical Operations


Operation
C
Java
MIPS
Shift left
<< 
<< 
sll
Shift right
>> 
>>> 
srl
Bitwise AND
&
&
and, andi
Bitwise OR
|
|
or, ori
Bitwise NOT
~
~
nor

  1. Shift operation

op
rs
rt
rd
shamt
funct
6
5
5
5
5
6
  • shift left logical (sll)
A left shift moves every bit to the left. The low-order bit  is replaced by a zero bit and the high-order bit is discarded. For example, if the original binary number is 0011010011011110 and the condition is shift it left (logical) by two. Therefore, the answer is 1101001101111000.
 
  • shift right logical (srl)
The high-order bit gets zeros and the low-order bits are discarded.
There are 2 types of right shift: logical and arithmetic. Both types shift the bits to the right, and the low order bit is lost. The difference is in what is shifted into the high order bit.

In a logical shift, a zero is shifted into the high order bit. In an arithmetic shift, the high order bit is sign extended: the value shifted into the high order bit matches the sign of the number. So if the number is positive, a zero is shifted in, and if the number is negative, then a one is shifted in. For example, if the value is 0100110111 and  the condition is shift it right(logical) by one.Therefore, the answer is 0010011011.

If the number is positive, then arithmetic right shift looks just like logical right shift, since 0's are shifted into the high order bits.  For example, if the value is 1101001101 and the condition is shift it right(logical) by one.Therefore, the answer is 1110100110.

     2.  AND Operation
  • 1+1=1
  • 1+0=0
  • 0+0=0
  • Therefore, 1011001101 and 1000111101 is equal to 1000001101
     3. OR Operation
  • 1+1=1
  • 1+0=1
  • 0+1=1
  • 0+0=0
  • Therefore, 1011001101 0r 1000111101 is equal to 1011111101
     4. NOT Operation
  • 1 change to 0
  • 0 change to 1 
  • Therefore, 1011001101 will change to 0100110010
 
 

No comments:

Post a Comment