checking if binary numbers are palindromic

This is a discussion on checking if binary numbers are palindromic within the C Programming forums, part of the General Programming Boards category; hey all, jus need a lil help. ok. got an assignment to make a C program to find all the ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    3

    Question checking if binary numbers are palindromic

    hey all, jus need a lil help. ok. got an assignment to make a C program to find all the palindromic primes from 1 to 10000, convert them to binary and chek if the binary representation is palindromic for each, then output only the palindromic primes to a txt file with time stamps.
    well i think i kinda have it but cant really code the last part which is taking the binary numbers and cheking if they are palindromic. teacher said we can get it using bitwise operators but i have no idea how to use them to do that. i kno i either hav to compare the first and last digit, then the second and the second to last digit, and so on to see if its a palindrome. or take the number and print it backwards and check if they are ==. so yea i dont kno how to take my binary number which i am already printing and code it to chek if its a palindrome . any help? thanks

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    if you already have a way to check if a prime (or any number) is 'palindromic', doing it with a binary number shouldnt be much different. how did you do it with the other (base-10) numbers? if you converted the number to a string first, then your function should work with the binary numbers to with no change. just convert the binary number to a string before you call the function.

    if you dont have a function to convert a number to a string, look at this link. notice the comment and sample code in the 'portability' section.

    hope it helps

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    3
    thanks alot will look into that link and see if i can use it. thing is i dont have a function that tests if an integer is a palindrome. thanks again.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    3
    Yup it worked, thanks alot nadroj. big help. i used the function and then made a palindrome function.peace.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. denary to binary problems
    By redruby147 in forum C Programming
    Replies: 6
    Last Post: 02-09-2009, 05:21 PM
  2. Binary numbers?
    By Cherry65 in forum C++ Programming
    Replies: 11
    Last Post: 12-17-2008, 10:10 AM
  3. something about binary numbers in c
    By louis_mine in forum C Programming
    Replies: 1
    Last Post: 02-09-2005, 10:22 PM
  4. Print binary numbers to disk file, problem
    By Guti14 in forum C Programming
    Replies: 4
    Last Post: 10-04-2004, 08:33 AM
  5. Binary representation of numbers...
    By roc in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2003, 08:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21