| | |
Check Palindrome: Binary & Decimal
Please support our C++ advertiser: Intel Parallel Studio Home
# include <iostream> # include <conio.h> using namespace std; void binPaldrome(unsigned int); void showbits(unsigned int); int main() { unsigned int no; for(;;) { printf("Check Palindrome "); system("time /t"); switch(getch()) { case 27: return 0; case 13: cout<<"Enter the no: "; cin>>no; binPaldrome(no); } } return 0; } void binPaldrome(unsigned int n) { unsigned int copy=n, rev=0; while(copy>0) { rev=(rev*10)+copy%10; copy/=10; } printf("%d ",n); showbits(n); if(rev==n) printf("\nDecimal Palindrome %c", 251); else printf("\nDecimal Palindrome X"); int i, j, andmask, c1, c2, flag=0; for(i=15; i>=0; i--) { andmask=1<<i; c1 = n & andmask; if(c1!=0) break; } for(j=0;;j++) { andmask=1<<j; c2 = n & andmask; if((i-2)==j) break; if(c1==c2 || (c1!=0 && c2!=0)) { i--; andmask=1<<i; c1 = n & andmask; } else { flag=1; break; } } if(flag==0) printf("\nBinary Palindrome %c", 251); else printf("\nBinary Palindrome X"); printf("\n"); } void showbits(unsigned int n) { int i, k, andmask; for(i=15; i>=0; i--) { andmask=1<<i; k = n & andmask; k==0? printf("0") : printf("1"); } }
Similar Threads
- binary to decimal (C++)
- how to convert Binary numbers to decimal numbers and decimal numbers to binary (C++)
- Code Snippet: Binary to Decimal (C)
- Convert Binary to Decimal and from Decimal to Binary (C++)
- check whether a palindrome can be formed from a given stirng (Java)
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets



