Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. int is_palindromeBinary(int num)
  2. {
  3. char c[SIZE];
  4. int bitLength = 0;
  5. int copy = num;
  6. while (copy != 0) // סופרת את מספר הביטים שבמספר המתקבל
  7. {
  8.  
  9. copy = copy>>1;
  10. bitLength++;
  11. }
  12.  
  13. int num1 = 0, i = 0, j = bitLength - 1;
  14.  
  15. num1 = num;
  16. while (num != 0) // מעתיקה לתוך תאי המחרוזת את הביטים של המספר משמאל לימין
  17. {
  18. c[j] = num&1;
  19. j--;
  20. num = num>>1; /* Shifting right the given number by 1 bit */
  21. }
  22. printf("The number %d in binary is:\n", num1);
  23. for (i = 0;i < bitLength;i++)
  24. {
  25. printf("%d", c[i]);
  26. }
  27. printf("\n");
  28.  
  29.  
  30. char temp[SIZE];
  31. int flag = 1;
  32. for (i = 0, j = bitLength - 1;i < bitLength, j >= 0;i++, j--) // מעתיקה לתוך מחרוזת זמנית את תאי המחרוזת המקורית
  33. {
  34. temp[j] = c[i];
  35. }
  36. for (i = 0;i < bitLength;i++) // בודקת האם המחרוזת המקורית שווה למחרוזת הזמנית (פלינדרום)מימין לשמאל
  37. {
  38. if (temp[i] != c[i])
  39. {
  40. flag = 0;
  41. }
  42. }
  43. return flag;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement