Question: I need help with this program. When I put input 0x7f I should get output 0b01111111. When I put 0x3f I should get 0b00111111. WHen

I need help with this program. When I put input 0x7f I should get output 0b01111111. When I put 0x3f I should get 0b00111111. WHen i put 0x0 I should get 0b0. When I put 0x5 I should get 0b0101. For some reason this program doesn't include the zeros, but I need them to be included. PLEASE help me fix this.

#include #include using namespace std; int main() { string hex,dec; // string containing hexadecimal and binary numbers bool invalid_number = false; // if number is invalid hexadecimal number // input of hexadecimal number cout<<" Enter a hexadecimal number : "; getline(cin,hex); dec=""; // assign dec to empty string // since the first 2 character of hexadecimal starts from 0x, ignore them during conversion for(size_t i=2;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!