| | |
Check Palindrome: Binary & Decimal
# 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 |
api array based binary bitmap business c++ c/c++ char class classes code coding commentinghelp compile console conversion count decide delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez graph guess gui homeworkhelp homeworkhelper iamthwee ifpug ifstream incrementoperators infinite input int integer java lib linkedlist linker loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem proficiency program programming project python random read recursion reference rpg string strings temperature template templates test text text-file tree url variable vector video win32 windows winsock word wordfrequency wxwidgets



