Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

my code : need help fixing error at line 13 get no operator != matches these operands please help #include #include #include #include using namespace

my code : need help fixing error at line 13 get no operator != matches these operands please help

#include #include #include #include

using namespace std;

void printBinary(char ch) { int val = ch; int num = 128; for (int i = 0; i < 8; ++i) { cout << (val / num) != 0; val = val % num; num /= 2; } }

void printStr(string str) { int val = 0; int num = 128; for (int i = 0; i < str.length(); ++i) { if (str[i] == '1') { val += num; } num /= 2; if ((i + 1) % 8 == 0) { cout << (char)val; num = 128; val = 0; } } cout << endl; }

int main() { cout << "Enter a string to convert to binary: "; string str; getline(cin, str); for (int i = 0; i < str.length(); ++i) { printBinary(str[i]); } cout << endl; cout << "Enter a binary string to convert to ascci: "; getline(cin, str); printStr(str); return 0; }

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

Students also viewed these Databases questions