CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2022

    New with C programming, question about a loop situation

    Hi all,

    I'm new to the C language, trying to do an exercise where I have to print the "fifth" bit of a given number (0 to 255). The condition of this exercise is to not use operators of affectation (such as >>x or <<x, etc.).

    I need to do it with modulo and divisions.

    I'm really blocked, tried many things, and also searched for solutions on the
    web, but no success so far. If anyone could guide threw, I would be thankful as heck.

    Pasting my poorly written code, then I will comment as to what is my idea behind this.

    int main(void)


    int number_user;
    int bit;
    int i;

    printf("Please put an integer between 0 and 255: ");
    scanf("%d", &number_user);

    i = 0;

    while (i <= 4)


    number_user /= 2;

    bit = number_user % 2;

    printf ("your fifth bit is %d: \\n", bit);

    return EXIT_SUCCESS;

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: New with C programming, question about a loop situation

    You already got the answers in your previous thread:
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width