Working on...

your queries, use contact form

23 Oct 2020

C language program to perform basic logic operations like NOT/complement/inverse, AND, OR, XOR, Left shift, Right shift

 //CLP to perform basic logic operations like NOT/complement/inverse, AND, OR, XOR, Left shift, Right shift

 

# include<reg51.h>

void main(void)

{

unsigned char x,y, a,b,c, d,e,f, p,q,r; //define variables

 //NOT operation

x=0x12; //first 8-bit number

P0=0x00; //declare port 0 as output port

y=~x; // perform NOT operation

P0=y; //display result on port 0

 

//AND operation

a=0x12; //first 8-bit number

b=0x34; //second 8-bit number

P1=0x00; //declare port 1 as output port

c=a&b; // perform AND operation

P1=c; //display result on port 1

 

//OR operation

d=0x12; //first 8-bit number

e=0x34; //second 8-bit number

P2=0x00; //declare port 2 as output port

f=e|d; // perform OR operation

P2=f; //display result on port 2

 

//XOR operation

p=0x12; //first 8-bit number

q=0x34; //second 8-bit number

P3=0x00; //declare port 3 as output port

r=q^p; // perform XOR operation

P3=r; //display result on port 3

 

//Left shift operation

x=0x12; //first 8-bit number

P0=0x00; //declare port 0 as output port

y=x<<1; // perform Left shift operation

P0=y; //display result on port 0

 

// Right shift operation

x=0x12; //first 8-bit number

P1=0x00; //declare port 0 as output port

y=x>>1; // perform Right shift operation

P1=y; //display result on port 1

 

while(1);

}

 

OR simplified one

 

# include<reg51.h>

void main(void)

{

unsigned char x,y,z, a,b,c,p,q; //define variables

 

x=0x12; //first 8-bit number

y=0x34; //second 8-bit number

P0=0x00; //declare port 0 as output port

P1=0x00; //declare port 1 as output port

P2=0x00; //declare port 2 as output port

P3=0x00; //declare port 3 as output port

 

z=~x; // perform NOT operation

P0=z; //display result of addition on port 0

 

a=x&y;//perform AND operation

P1=a;// display result of subtraction on port 1

 

b=x|y;// perform OR operation

P2=b;//display result of multiplication on port 2

 

c=x^y;//perform XOR operation

P3=c; // display result of division on port 3

 

p=x<<1;//perform Left shift operation

P3=p; // display result of division on port 3

 

q=x>>1;//perform Right shift operation

P3=q; // display result of division on port 3

  

while(1);

}


Video for the same 

No comments:

Post a Comment