Please help with this problem

Joined
Aug 17, 2024
Messages
3
Reaction score
0
i don't know if that's what you're looking for, but here it is:

C++:
#include <iostream>
#include <thread>
#include <chrono>

int main() {
    // Initialize two bits
    int bit1 = 0; // Represents the least significant bit (LSB)
    int bit2 = 0; // Represents the most significant bit (MSB)

    // Simulate counting from 0 to 3
    for (int count = 0; count < 4; ++count) {
        // Print the current state of the two bits
        std::cout << "Count: " << count << " (Bits: " << bit2 << bit1 << ")" << std::endl;

        // Increment the bits
        if (bit1 == 0) {
            bit1 = 1; // Set LSB to 1
        } else {
            bit1 = 0; // Reset LSB to 0
            if (bit2 == 0) {
                bit2 = 1; // Set MSB to 1
            } else {
                bit2 = 0; // Reset MSB to 0
            }
        }

        // Optional: Add a delay to visualize the counting process
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }

    return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,871
Messages
2,569,919
Members
46,171
Latest member
A.N.Omalum

Latest Threads

Top