Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C programming logic to be discussed

Status
Not open for further replies.

saumya_85

Advanced Member level 4
Full Member level 1
Joined
Mar 18, 2009
Messages
107
Helped
6
Reputation
12
Reaction score
5
Trophy points
1,298
Location
INDIA
Visit site
Activity points
1,948
for(i=0; i<SAMPLE; i=i+1)
{
x = ((int32_t)(input)) * ((int32_t)(input));
uadd32_64(x,Sum);
}


Code C - [expand]
1
2
3
4
[SIZE=4]  Sum[1]= Sum[1] >> 5;
  temp =  Sum[0] << 27;
  Sum[1]= Sum[1]| temp;
  Sum[0]= Sum[0] >>5; [/SIZE]



What is the meaning of above << and >> logic
 

The << and >> are binary right shift and binary left shift accordingly.

C/C++ Operators

Code:
#include <stdio.h>

main()
{

   unsigned int a = 60;	/* 60 = 0011 1100 */  
   unsigned int b = 13;	/* 13 = 0000 1101 */
   int c = 0;           

   c = a & b;       /* 12 = 0000 1100 */ 
   printf("Line 1 - Value of c is %d\n", c );

   c = a | b;       /* 61 = 0011 1101 */
   printf("Line 2 - Value of c is %d\n", c );

   c = a ^ b;       /* 49 = 0011 0001 */
   printf("Line 3 - Value of c is %d\n", c );

   c = ~a;          /*-61 = 1100 0011 */
   printf("Line 4 - Value of c is %d\n", c );

   c = a << 2;     /* 240 = 1111 0000 */
   printf("Line 5 - Value of c is %d\n", c );

   c = a >> 2;     /* 15 = 0000 1111 */
   printf("Line 6 - Value of c is %d\n", c );
}

Output:
Line 1 - Value of c is 12
Line 2 - Value of c is 61
Line 3 - Value of c is 49
Line 4 - Value of c is -61
Line 5 - Value of c is 240
Line 6 - Value of c is 15

BigDog
 
Hi saumia..

in this program you are trying to find the sum of squares in the input array (may be for RMS) they are 32 bits wide but the result will be in 64 bits wide...

may be the full function uadd32_64 adds the values in 64 bit format to the array sum...

>> and << operators are used for shifting for example

4 is 0000 0100
after shifting one position right
0000 0010

Tricks:
when right shifting the value will be divide by 2 and it will be multiplied when left shifting..
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top