Thread: Decimal To Binary using bitwise

  1. #1
    Registered User
    Join Date
    Nov 2013
    Posts
    1

    Decimal To Binary using bitwise

    Hi.. i have no clue how to do this program i can easily do it in a simple for loop but i have to do this program with the following directions:

    1. Write a function called bitN() that returns the value of bit N in number, where number is the first parameter, and N is the second. Assume N of the least significant bit is zero and that both parameters are unsigned int's. (A simple one-liner will suffice)

    2. Write a main() function that uses bitN() to convert a decimal integer into its binary equivalent. Obtain the integer to convert from the first command-line argument.

    3.
    Use the expression
    unsigned int numBits = sizeof(unsigned int)*CHAR_BIT;
    to get the number of bits in an unsigned int. (Include limits.h to get the definition for CHAR_BIT.)


    Please Help!!!!!!
    Last edited by sekhon92; 11-15-2013 at 05:33 PM.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Read this link.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  3. #3
    Registered User HelpfulPerson's Avatar
    Join Date
    Jun 2013
    Location
    Over the rainbow
    Posts
    288
    Well, in the FAQ, there are examples in C++ that you could use to help you along and learn how different operators work : FAQ > Bit manipulation - Cprogramming.com
    You can also see this( again in the FAQ ), to continue learning about the operators and more specific contexts they can be used : Tutorials - Bitwise Operators and Bit Manipulations in C and C++ - Cprogramming.com
    "Some people think they can outsmart me, maybe. Maybe. I've yet to meet one that can outsmart bullet" - Meet the Heavy, Team Fortress 2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. binary to decimal
    By yigster in forum C Programming
    Replies: 2
    Last Post: 03-31-2009, 04:00 AM
  2. binary to decimal
    By rs07 in forum C Programming
    Replies: 3
    Last Post: 09-14-2008, 12:52 PM
  3. Binary to Decimal-- Need help
    By Evandb in forum C Programming
    Replies: 5
    Last Post: 05-18-2004, 10:20 AM
  4. binary - decimal
    By curlious in forum C++ Programming
    Replies: 5
    Last Post: 07-31-2003, 02:25 PM
  5. decimal to binary, decimal to hexadecimal and vice versa
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 12-08-2001, 11:07 PM

Tags for this Thread