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 8955013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:26:48+00:00 2026-06-15T14:26:48+00:00

Write a program that reads an integer value from the keyboard into a variable

  • 0

Write a program that reads an integer value from the keyboard into a variable of type int, and uses one of the bitwise operators (i.e. not the % operator!) to determine the positive remainder when divided by 8.

For example, 29 = (3×8)+5 and 14 = ( 2×8)+2 have positive remainder 5 and 2, respectively, when divided by 8.

I tried to search how can I solve it. What I did is to break given examples numbers into binary.

29 => 101001
8  => 001000
5 =>  000101

I don’t know what is operation I should do with 29 and 8 to get result 5 in binary.

While searching there’s some guys said that we should do (& operation with 7 )

remainder = remainder & 7 ;

Then I tried to do this with Value itself

value = value & 7 ; 

and Here’s my code After doing it …

#include <iostream>

using std::cout;
using std::endl;
using std::cin;

int main()
{
  int value = 0;
  int divisor = 8;
  int remainder = 0;

  cout << "Enter an integr and I'll divide it by 8 and give you the remainder!"
       <<endl;
  cin >> value;

  value = value & 7;
  remainder = value & divisor;
  cout << remainder;

  return 0;
}

It gave me result 0 when I use value 29. I don’t know what I wrote was right or not.

  • 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-15T14:26:49+00:00Added an answer on June 15, 2026 at 2:26 pm

    Since 8 is exactly 2^3, the modulo-8 remainder of any number is composed of its last three binary digits, i. e. it equals the number bitwise-and 7:

    unsigned rem8 = number & 7;
    

    (7 is 111 in binary, that’s why.)

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

Sidebar

Related Questions

So, I'm trying to write a c program that reads input piped into the
I'm learning java and I have made simple program that simply reads value from
I am trying to write a simple program that reads integers from a data
I am trying to write a program that reads from the console a positive
I'm trying to write a program that reads broadcasted UDP datagrams in linux.I'm a
I am trying to write a Java program that reads an input file consisting
Below is the program that I wrote. /******************************************************************************* * This program reads EOF from
This is a homework assignment, I have to write a program that reads a
I have to write a program that finds square root of an integer that
I have a Java program that reads some text from a file, line by

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.