My homework is to create a program to scan in and add binary numbers and print them like so
Enter a binary number: 1
sum = 1 decimal 1 hex and 00000001 binary
Enter a binary number: 10
sum = 3 decimal 3 hex and 00000011 binary
etc.
I know that bit manipulation and input and output of strings is necessary to create this program, but I'm not experienced with either. The code I have compiles, but I am unable to make it do anything useful, and most of it is wrong. My do loop is probably wrong and I don't understand how to properly use bit manipulation. I'm rather clueless, can anyone give me some ideas on what to do next?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "stdafx.h"
#include "stdio.h"
#include "math.h"
#include "iostream"
#include "string"
using namespace std;
int sum = 0;
int i = 0;
int c = 0;
int Q;
string binaryInput;
int main()
{
cout << ("Enter a binary number: "); //Prompts the user for input
cin >> binaryInput; //Writes the binary input to cin
do { //do loop to read the binary one digit at a time
i++;
cout << binaryInput[i]; //I don't understand how to output a specific digit of the string and manipulate it
c = binaryInput[i];
if (c = Q)
break;
else;
sum = sum + c * 2 * i; // supposed to be sum = sum + binaryInput[i] * pow(2,i), this is where the binary is converted to decimal
printf("nsum = %*d ", 3, sum);
printf("decimal %*x " , 2, sum);
printf("hex %08d binary", sum);
} while (i
Wierd echo error?
Hi, i got the most wierd php error ever and i don't know why..Code: echo "<td><strong>MP:</strong></td>"; echo
Get ID from Database when Posting with a HTML Form
I have a form I am submitting to a MySql database. Each product has an ID # attached to it that auto_increment.I need to pull the auto incremented ID # for the entry I just posted onto the page so the
Not reloading page after php form submit
Hello helpful souls out there. You guys have come through for me in the recent past and I'm hoping someone out there can either help me or point me in the right direction.I have the following site,
Links not updating
I'm trying to fuel a simple navigation system for a news section. It works fine when it comes to retrieving and displaying data, but if I click on a valid link in the following code, the content and
Trouble verifying database password
Thankyou to everyone who responded to my last post (I can't find the posting, it has been buried). I am currently making a login form and the associated php code. It all seems to work apart from the
Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and then store it in a local folder on my site. That way, I would only need to pull the xml file once in
Strip Slashes Help
I've got a script that i've downloaded of the net to edit multiple fields from my sql database, and works fine EXCEPT I want to add the strip slashes bit to it so it will save what I type in. However,
. and .. appearing instead of pictures
First of all, thanks very much for providing this forum. It is very much appreciated!My son-in-law created a php script for my website about 10 years ago to show pictures like a manual slideshow, and
Post PHP form to non-existing page
The company that I work for host their PHP code on IIS on a Windows server, no Apache, so no mod_rewrite. I recently wrote a custom framewok that is loosely based on Codeigniter. To get SEF URL's 'n
Select Rows as Columns..
is there a way to select COLUMN_NAME from user_tab_columns where table_name='TABLENAME';