Tuesday, September 23, 2014

C Programming : Is a number power of '2'?

#include


int main()
{
        int num = 0;int k = 0;
     
        printf("enter a number");
        scanf("%d",&num);
        printf("\nIsPoweroftwo = %d\n",isPowerOfTwo(num));

        while(1) {
                printf("\nDo you want to continue? 1 or 0\n");
                scanf("%d",&k);

                  if(k){
                        printf("enter a number");
                        scanf("%d",&num);
                        printf("\nIsPoweroftwo = %d\n",isPowerOfTwo(num));
                   } else {
                      break;
                   }
       }    
 }

int isPowerOfTwo (unsigned int x)
{
       return ((x > 0) && ((x & (~x + 1)) == x));
}

Saturday, September 20, 2014

C Programming : Run Length Encoding for a given string


int main()
{
int cnt = 0;
int j = 0,i = 0,k=0;
char str[1000] = "llllggg$$$$$$(((((((@@@@@@@aaiiiiiahaag;;;;;a,,,,,////)))gsssdsssggggggggkkkkkkjjj";

char str_enc[50];
char str_n[10] = {0};
char val = '\0';

val = str[0];
for(i = 0 ;str[i]!='\0'; i++) {
if(val == str[i]) {
cnt++;
} else {
val = str[i];
snprintf(str_n,8,"%d",cnt);
k = 0;
while(str_n[k] != '\0')
str_enc[j++] = str_n[k++];
str_enc[j++] = str[i-1];
memset(str_n,0,strlen(str_n));
cnt = 1;
}
}

snprintf(str_n,8,"%d",cnt);

k = 0;
while(str_n[k] != '\0')
str_enc[j++] = str_n[k++];
str_enc[j++] = str[i-1];
str_enc[j] = '\0';

memset(str_n,0,strlen(str_n));
printf("%s\n",str_enc);

}

OUTPUT
4l3g6$7(7@2a5i1a1h2a1g5;1a5,4/3)1g3s1d3s8g6k3j

Interview Questions : ARM and General Embedded System


General Embedded System
1. State the differences between a FIQ and IRQ?
2. Describe steps for a wake-up of a new IP component? How to write a device driver?
3. What things you do not do in ISR?

ARM
1.  Explain different ARM registers especially SPSR and CPSR.
2.  Explain various processor modes?
3. What is use of Thumb Instruction?
4. Explain how interrupt controller works in ARM.


Interview Questions : C Programming and Data Structures

1. State the use of 'Volatile'. What happens when cache is disabled in a system?
2. Program for reversal of linklist.
3. Difference between declaration and definition.
4. Explain pointer to const and constant pointer.
5. Tell me declaration of a function pointer for a function which takes no argument but returns a pointer to char.
6. Dynamically allocate double dim array.
7. Difference between k++; and ++k; in terms of efficiency.
8. How to find sizeof of an unknown structure without using sizeof operator. Assume that you only know the name of the struct not its components.
9. How to find or update 'n' th byte of any integer.
10.How to set 'n' bits of a number from 'p'th position.
11.How to find a 'n'th node from last node of a single linklist while traversing from root.
12.How to find whether two linklist merges or not, and also where they merge.
13.How to find whether there is a cycle in a linklist.
14.How to determine whether a system is Little Endian or Big Endian?
15.How to change Endianness of a number?
16.How to rotate 'n' bits of a number?
17.How to find whether a number is power of 2 or not?
18.Finding number of set bits in a number without a loop?
19.How to toggle 'n' bits of a number from 'p'th position.
20. Declare a function pointer which takes a pointer to an array and also returns a pointer to an array.
21. What are 'Variadic' functions?
22. How would you find pattern in a string.
23. Explain how compiler manages an Inline function? What is the difference between Inline and Macros?