Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int is_palindromeBinary(int num)
- {
- char c[SIZE];
- int bitLength = 0;
- int copy = num;
- while (copy != 0) // סופרת את מספר הביטים שבמספר המתקבל
- {
- copy = copy>>1;
- bitLength++;
- }
- int num1 = 0, i = 0, j = bitLength - 1;
- num1 = num;
- while (num != 0) // מעתיקה לתוך תאי המחרוזת את הביטים של המספר משמאל לימין
- {
- c[j] = num&1;
- j--;
- num = num>>1; /* Shifting right the given number by 1 bit */
- }
- printf("The number %d in binary is:\n", num1);
- for (i = 0;i < bitLength;i++)
- {
- printf("%d", c[i]);
- }
- printf("\n");
- char temp[SIZE];
- int flag = 1;
- for (i = 0, j = bitLength - 1;i < bitLength, j >= 0;i++, j--) // מעתיקה לתוך מחרוזת זמנית את תאי המחרוזת המקורית
- {
- temp[j] = c[i];
- }
- for (i = 0;i < bitLength;i++) // בודקת האם המחרוזת המקורית שווה למחרוזת הזמנית (פלינדרום)מימין לשמאל
- {
- if (temp[i] != c[i])
- {
- flag = 0;
- }
- }
- return flag;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement