Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9190081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:22:49+00:00 2026-06-17T20:22:49+00:00

I’m trying to write a basic practice with C, working with Binary and Hex.

  • 0

I’m trying to write a basic practice with C, working with Binary and Hex. I made a method to print the multiples of 2 (powers of 2) and a separate method to print out the Hex form of that multiple of 2.

#include <stdlib.h>
#include <stdio.h>

const char one = 1;
const int bits = 31;

void    print2       ()
{
    unsigned int  u = (int)one;
    unsigned int j;

    printf("The powers of 2 are:\n");

    for(j=0;j<bits;j++)
    {
            unsigned int temp = u<<j;
            printf("%d\n",abs(temp));
            printhex(temp);
    }

    printf("\n\n");
}

void    printhex       (unsigned int   u)
{
    printf("0x%08X\n",u);
}

int main ()
{
    print2();
    return(EXIT_SUCCESS);
}

What I don’t understand is why I get an error “conflicting types” from calling on the method “printHex”. I specifically ask for an unsigned integer and when I call the method within the parameter (which I assume to be unsigned integer “temp”), the compiler does not accept.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:22:50+00:00Added an answer on June 17, 2026 at 8:22 pm

    You run into problems because you’ve not provided a prototype for printhex() before you use it.

    Either put printhex() physically before print2() in the source file, or add a declaration:

    extern void printhex(unsigned int u);
    

    before print2() is defined. (Don’t declare printhex() inside print2(); even though it is syntactically legal, it is bad practice to do so.)


    When the compiler runs across the call printhex(temp), it assumes (under C89 rules) that it is a function that returns an int with an indeterminate argument list (but not one which is formally a variable argument list — varargs functions like printf() must always have a prototype in scope). When you subsequently define it as returning void, it gets upset and reports the conflicting type error. Under C99 rules, you are supposed to have a prototype in scope before using a function.

    I’d like to comment on your layout; it’s a little unorthodox.

    The function definitions don’t need as many blanks in them (use less white space in the function definitions):

    void    print2       ()
    void    printhex       (unsigned int   u)
    

    would be:

    void print2(void)
    void printhex(unsigned int u)
    

    if I were writing them. I write functions with the explicit (void) in the definition so it matches the prototype notation for the function. Actually, if I was writing them, they’d more likely be prefixed with static. If the function I write is not going to be used outside the source file it is in, then I make it static automatically. Further, if the function is defined as static before it is used, then I don’t need a second declaration of the function. If a function is not static, there should, in my book, be a header that declares the function, and that header should be used in both the file that defines the function and in the files that use the function. This ensures consistency.

    Also, you use abs(temp) which is slightly odd; it is a long-winded way of converting the unsigned int to a signed int, but you’d do better to write:

     printf("%u\n", temp);
    

    Finally, I’d suggest you use more white space in the for loop:

    for (j = 0; j < bits; j++)
    

    No space before commas or semicolons; spaces around binary operators (but not unary operators, or very tightly binding operators such as subscripts or member (. or ->) operators).

    Your output interleaves hex with decimal; you might find it better to use:

    printf("%10u ", temp);
    

    to put the decimal value right justified on the line, leaving the hex to appear after it on the same line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I know there's a lot of other questions out there that deal with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.