Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help with Coding C++ 4 functions. I've attached my code below it all. I need help with my code Many functions below will refer to

Help with Coding C++ 4 functions. I've attached my code below it all. I need help with my code

Many functions below will refer to data type called "byte". This is simply shorthand for an "unsigned char". Other than string::length(), you may not use any STL functions. Instead, you must implement the needed functionality using logical and bitwise operations.

  • byte msb(byte)

    This function returns the MSB (bit 7) of the given unsigned char shifted to the LSB position (bit 0).

  • bool overflow(byte, byte, byte)

    This functions checks if the result of an addition has produced overflow. You may recall that this involves comparing the MSBs of the two operands and the result. Instead of first extracting the MSBs, you may apply the same bitwise operations to the three numbers and then extract the MSB of the result.\

  • byte str2bin(string &)

    Given a binary number as an ASCII string, this function computes and returns the corresponding unsigned char. Tip: Replace multiplication with bit-shifting and use bitwise OR instead of addition when setting a bit.

  • bool isBIN8(string &)

    This function checks that the binary number considered is between 1 and 8 characters long and that each character is either 0 or 1. If either check fails, the function returns false. Otherwise, true.

#include #include #include using namespace std;

typedef unsigned char byte;

byte msb(byte); bool overflow(byte, byte, byte); byte twoscomplement(byte);

byte str2bin(string &); string bin2str(byte); string bin2dec(byte);

bool isBIN8(string &); bool isVALID(string &);

int main(int argc, char *argv[]) { string sX, sY; string op;

cout << "X> "; cin >> sX; if (cin.eof()) return 1;

if (!isBIN8(sX)) { cout << "error: not 8-bit binary number "; return 1; }

cout << "Y> "; cin >> sY; if (cin.eof()) return 1;

if (!isBIN8(sY)) { cout << "error: not 8-bit binary number "; return 1; }

cout << "op> "; cin >> op; if (cin.eof())

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And Transact SQL

Authors: Lucy Scott

1st Edition

1974679985, 978-1974679980

More Books

Students also viewed these Databases questions

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago