Note 1
##### Take Note:

Take a note while surfing.

##### Note With Ink

Give your Note a Colorful Tag.

##### Easy to Access

Stay on same information and in Sync wherever you are.

Note 2
##### Take Note:

Organize your information,It may take Shape.

##### Easy to Access

Easy to pull up your content from anywhere anytime.

Note 3
##### Take Note:

Don't Let information to miss,Because it take shape

##### Note With Ink

Simple an Easy Way to take a note.

##### Easy to Access

Get the same in next visit.

Take Quiz (Monsoon) Beta Version !!
Do You have Qs. in your Mind ??? Ask it as Qs. or MCQs or create it as polling Live Now !!

11 / 348

Write a program to find string is palindrom or not.

Input : NA

Output : NA

|  Basics | | | |  Fresher
 
#include <iostream>using namespace std;int main(){    char string1[20];    int i, length;    int flag = 0;        cout << "Enter a string: "; cin >> string1;        length = strlen(string1);        for(i=0;i < length ;i++){        if(string1[i] != string1[length-i-1]){            flag = 1;            break;       }    }        if (flag) {        cout << string1 << " is not a palindrome" << endl;     }        else {        cout << string1 << " is a palindrome" << endl;     }    system("pause");    return 0;}


Tags:IBM PEOL

12 / 348

Write an efficient program to count the number of bits set in an integer number

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include<iostream>using namespace std;// count the no. of set bits in a positive integerint countSetBits(unsigned int num) {   unsigned int count = 0;   while (num) {      // bitwise AND operation to check if the      // leftmost bit is set or not      // if set, increment the count      count += num & 1;      // left shift the nm by one position      num >>= 1;   }   return count;}//mainint main() {   unsigned int num = 6;   unsigned int no_set_bits = countSetBits(num);   cout<<"\nNo. of set bits :: "<<no_set_bits;   cout<<endl;   return 0;}


Tags:No Tags on this question yet!

13 / 348

Write an efficient program to set the bits in a given range(start and end position given) in an integer number

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
import java.util.*;import java.lang.*;import java.io.*;class SetBits{    public      int start;      int end;      int num;public SetBits(int s, int e, int n) {     start = s;    end = e;    num = n; }  void set()  {    for (int i = start; i<= end; i++)      num = num | (1<<i);  }}class ABC{ public static void main(String args[]) {  int start,end, num;  Scanner in = new Scanner(System.in);  System.out.println("Enter any number");  num = in.nextInt();  System.out.println("Enter starting position ");  start = in.nextInt();  System.out.println("Enter ending position ");  end = in.nextInt();       SetBits obj = new SetBits(start,end,num);  obj.set();  System.out.printf("number after bits set  "+obj.num); }}


Tags:No Tags on this question yet!

14 / 348

Write an efficient program to swap the odd and even bits in an integer

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include <stdio.h>#include<iostream>using namespace std; unsigned int swapBits(unsigned int x){    // Get all even bits of x    unsigned int even_bits = x & 0xAAAAAAAA;     // Get all odd bits of x    unsigned int odd_bits = x & 0x55555555;     even_bits >>= 1; // Right shift even bits    odd_bits <<= 1; // Left shift odd bits    return (even_bits | odd_bits); // Combine even and odd bits}// Driver program to test above functionint main(){    unsigned int x = 23; // 00010111    // Output is 43 (00101011)        cout<<swapBits(x);    return 0;}


Tags:No Tags on this question yet!

15 / 348

Write an efficient program to check whether given number is power of two or not

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include<stdio.h>#include<iostream>using namespace std; #define bool int/* Function to check if x is power of 2*/bool isPowerOfTwo (int x){/* First x in the below expression is for the case when x is 0 */return x && (!(x&(x-1)));}/*Driver program to test above function*/int main(){isPowerOfTwo(31)?cout<<"Yes\n": cout<<"No\n";isPowerOfTwo(16)? cout<<"Yes\n": cout<<"No\n";return 0;}


Tags:No Tags on this question yet!

16 / 348

Write an efficient program to toggle all bits in a given integer number

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include <stdio.h>#include<iostream>using namespace std;int main(){    int num, n, newNum;    /*Reads a number from user*/   cout<<"Enter any number: ";     cin>>num;     /*Reads the bit number you want to toggle*/    cout<<"Enter nth bit to toggle (0-31): ";     cin>>n;     /* Left shifts 1 to n times then perform bitwise XOR with number and result of above*/    newNum = num ^ (1 << n);     cout<<"Bit toggled successfully.\n\n";     cout<<"Number before toggling %d bit: %d (in decimal)\n", n, num;     cout<<"Number after toggling %d bit: %d (in decimal)\n", n, newNum;     return 0;}


Tags:No Tags on this question yet!

17 / 348

Write an efficient program to swap the nibbles in a byte

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include <stdio.h>#include<iostream>using namespace std;/* function : swapTwoNibbles, to swap two nibbles of a given byte.*/unsigned char swapTwoNibbles(unsigned char n){    unsigned char num;    num= ( (n & 0x0F)<<4 | (n & 0xF0)>>4 );    return num;} int main(){    unsigned char number;    unsigned char revNumber;      cout<<"Enter an integer number (One byte number):";      cin>>number;    revNumber=swapTwoNibbles(number);    cout<<"\nEntered Number was : %u \nNumber after swapping nibbles : %u",number,revNumber;    return 0;}


Tags:No Tags on this question yet!

18 / 348

Write an efficient program to check the endianness of the machine

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include <stdio.h>#include<iostream>using namespace std;int main (){  unsigned int x = 0x76543210;  char *c = (char*) &x;   cout<<"*c is: 0x%x\n", *c);  if (*c == 0x10)  {   cout<<"Underlying architecture is little endian. \n";  }  else  {     cout<<"Underlying architecture is big endian. \n";  }  return 0;}


Tags:No Tags on this question yet!

19 / 348

Write an efficient program to convert a given number from little endian to big endian

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include <stdio.h> #include<iostream>using namespace std;/* function to show bytes in memory, from location start to start+n*/void show_mem_rep(char *start, int n) {    int i;    for (i = 0; i < n; i++)         printf(" %.2x", start[i]);    printf("\n");} /*Main function to call above function for 0x01234567*/int main(){   int i = 0x01234567;   show_mem_rep((char *)&i, sizeof(i));   getchar();   return 0;}


Tags:No Tags on this question yet!

20 / 348

Write an efficient program to covert decimal number into binary number

Input : NA

Output : NA

|  Bitwise Operator | | | |  Fresher
 
#include<iostream>
using namespace std;
int main()
{
long bin, dec = 0, rem, num, base = 1;
cout << "Enter the binary number(1s and 0s) : ";
cin >> num;
bin = num;
while (num > 0)
{
rem = num % 10;
dec = dec + rem * base;
base = base * 2;
num = num / 10;
}
cout << "The decimal equivalent of " << bin << " : " << dec << endl;
return 0;
}


Tags:TCS