Visual C++ :: Binary To Decimal Converter?
Oct 5, 2014
I'm trying to figure out why the binary to decimal part is not working correctly when the binary value finishes with a 1. In those cases, the decimal value shown in one unit smaller than it should be.
Code:
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
void Binary_to_Decimal(), Decimal_to_Binary(); //prototype for the 2 functions that contain the converters
int main() //the menu {
int a_Choice;
cout << "Enter 1 - for binary to decimal" << endl;
cout << "Enter 2 - for decimal to binary" << endl;
[code]....
View 2 Replies
ADVERTISEMENT
Feb 26, 2013
I'm trying to make a program that takes up to a seven digit binary number and converts it to its decimal equivalent. I'm still a beginner, so this might be a simple question but how do I stop the user from entering anything but 1s and 0s? This means no decimals or numbers other than 1 or 0.I already made it so it won't accept anything below 0 or above 1111111.
View 1 Replies
View Related
Mar 15, 2013
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int N=0, counter=0, counter1=0,counter2=0, temp=0, temp1=0,dec=0,result=0, moder=0;
[Code] .....
This is Binary to Decimal Converter. It's not working. Although Dry Run of this program works fine.
View 4 Replies
View Related
Sep 9, 2014
I was trying to program an decimal to binary converter (8-bits) in C. I am a complete beginner so I tried to put the 1's and 0's of the binary number as they come without reversing the order for beginning. I have seen example on the internet but didn't understand them so I decided to write it as I understood it. So, I typed the code as shown below:
Code:
#include <stdio.h>
#include <stdlib.h>
int main() {
int number;
int BitNum[8], x;
[Code] ....
The problem with the code is that if binary form has 0s in it then program displays a random number instead of a 0. For example if decimal is 7, it should print out 11100000 but it displays only 111(and some stupid numbers instead of 0). I have tried to solve it but failed.
View 7 Replies
View Related
Apr 18, 2012
Basically I have 2 questions.
1. Because of how limited integers are in terms of storage, the largest binary number i can give seems to be 1 111 111 111. Anything larger breaks the program. Is there any way to increase the largest input I can give without completely rewriting the program? I tried changing the num/numCounter (and the typecasting) to long doubles, but it just messed stuff up (or I did).
2. I'd also like to make it so that if someone inputs a non-binary number my program tells them so and stops. I figured a switch statement within the while loop would work (for when numCounter/divisor is negative or greater than 1), but I was wondering if instead it was possible to use an if statement that could break the while loop?
Anyway, here's the code:
Code:
#include <QtCore/QCoreApplication>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
[code]....
View 7 Replies
View Related
Jun 27, 2013
This program compiles, but has a bunch of logical errors. I know my problem is somewhere in the while loop that I have, but I can't figure out where. Here are some of the issues I am experiencing:
1. At the beginning of the program it asks you to enter a number, and when you do it does nothing while proceeding to the while loop where I have it asking the same question
Code:
"Please enter a number between 1 and 20 (Enter 0 to stop)
";
cin >> num;
cout << endl;
I want to be able to eliminate that first statement but if I only run this in the loop without the above statement the program will display nothing on the screen and proceeds to stop.
2. This code runs fine, except that if you make a mistake, it will prompt you to enter a valid number, however; it ignores your first response if the number you enter is valid and asks you to enter a valid number anyway. Once you enter it a second time, it will accept it and the program will continue on.
Code:
while(num != SENTINEL) {
cout << "Please enter a number between 1 and 20 (Enter 0 to stop) ";
cin >> num;
cout << endl;
Also if you type in 0 on your first response, it will prompt you that it is not a valid number and ask you to try again, instead of stopping the program like it is supposed to do. On your second response the program will accept your 0 and stop the program correctly.
//Write a program that displays the roman numeral equivalent of any decimal number between 1 and 20 that the user enters. The roman numerals should be stored in an array of strings and the decimal number that the user enters should be used to locate the array element holding the roman numeral equivalent. The program should have a loop that allows the user to continue entering numbers until an end sentinel of 0 is entered.
Input validation: Do not accept scores less than 0 or greater than 20
#include <iostream>
#include <string>
using namespace std;
int main() {
// Declare constants and variables
const int romanNum = 21; // Size of the elements in the array
[Code] ....
View 14 Replies
View Related
Dec 1, 2013
I have to create a converter but the results must be in 4 decimal places just like, if i Entered 5000mm the result would be 500.0000cm . what should I do ? I used Float function
View 1 Replies
View Related
Dec 19, 2014
Write a C++ program that adds three binary numbers of 8-bit each. Every number is stored into an array of 8 elements.
Example:
Array A
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array B
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
+
Array C
0 1 2 3 4 5 6 7
0 1 1 0 1 1 1 0
Store the result into an array D of 8 elements. Your program should show the decimal numbers for every binary number. Print screen of 6 answers. This means you should try your program six times with different numbers in every run and show the printed screen result.
View 5 Replies
View Related
May 23, 2013
I wrote this code purely for educational purposes. It also learn more about how exactly things look in memory. code I have right now ( I will likely add more and change it in the future) .....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
[Code].....
View 7 Replies
View Related
Jun 12, 2014
I wrote a program that converts Binary code to Grey code. It works, but I feel like it's highly inefficient. I've also been trying out Project Euler, but I seem to always turn to using vectors whenever solving a problem.
/* Binary to Grey Code Converter */
#include <iostream>
#include <vector>
using namespace std;
// Global Variables (I'd like to not use them because I've been told it's bad practice)
static int numDigits;
int digit;
vector<int> bin;
[Code] .....
View 1 Replies
View Related
Sep 21, 2014
I recently wrote a program to convert numbers to binary in c++, Well here it is:
#include <iostream>
void recur(int convert) {
if(convert == 0) //if input is 0 , return nothing. {
return;
}
recur(convert/2); // divide convert by 2, get only a 1 or 0
[Code] ....
View 13 Replies
View Related
Mar 30, 2014
I am very new to programming and have been working on a program that can receive decimals or binary numbers and convert them. The decimal --> binary works fine. For some reason I cannot figure out I cannot get the "BinaryToDecimal" function to perform. By putting a "printf" into the for-loop.
Code:
#include <stdio.h>#include <string.h>
#include <math.h>
char* ReverseString (char _result[]) {
int start, end, length = strlen(_result);
char swap;
for (start = 0, end = length-1; start < end; start++, end--)
[code]....
View 2 Replies
View Related
Nov 15, 2013
How to do this program i can easily do it in a simple for loop but i have to do this program with the following directions:
1. Write a function called bitN() that returns the value of bit N in number, where number is the first parameter, and N is the second. Assume N of the least significant bit is zero and that both parameters are unsigned int's. (A simple one-liner will suffice)
2. Write a main() function that uses bitN() to convert a decimal integer into its binary equivalent. Obtain the integer to convert from the first command-line argument.
3. Use the expression
unsigned int numBits = sizeof(unsigned int)*CHAR_BIT;
to get the number of bits in an unsigned int. (Include limits.h to get the definition for CHAR_BIT.)
View 2 Replies
View Related
Aug 24, 2014
I am trying to convert user inputted decimal to binary .
Code:
#include<stdio.h>
main() {
int a,b,c,d[30],i,j,e[30];
[Code].....
View 2 Replies
View Related
May 17, 2014
#include<iostream>
#include<conio.h>
using namespace std;
void main() {
int num1,num2,ans,rem;
[Code] .....
View 6 Replies
View Related
Sep 10, 2014
I have a code and am asked to modify it so that it will take as input as unsigned binary number up to 16 digits in length and convert it into its equivalent decimal number and output that decimal number.
All I know is that I use library function strlen() in <cstring> to calculate the length of the input string.
I also know I have to use something called pow(2,4);
//pow (); is found in cmath
I was told to use sum = sum >>16-l; (l is the length of />/>
#include <iostream>
using namespace std;
int main() {
[Code]....
View 4 Replies
View Related
Jul 25, 2013
So I tried debugging this program almost 10 times, each time finding a problem then making code to fix it, I used to get wrong values but then now after I changed the calculation from an infinity while loop to a for loop (because after some changes I realized that now I know the number of entries, meaning the start and the end of the loop) the program now displays no values at all. I checked it thoroughly and until the calculation process its functioning exactly the way it should but then the calculation breaks hell loose . Also the for loop that raises 2 to the power needed works fine too so it must be something with the other processes included in the calculation....
This used to be a function of a multiple value types conversion program, I isolated it for easier analysis as a lone standing program.
Code:
#include<iostream>
using namespace std;
int main() {
int d[10],e[10],anse=1,r,limit;
short int counterd=0,i,j;
float bind=0;
[Code] ....
View 11 Replies
View Related
Dec 7, 2014
I had an exercise to convert from decimal to binary with base 2, it was simple simple i did the following:
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void Conversion (int n);
[Code] .....
I then had an follow up exercise which was to replicate but for any base up to 10, i thought i would just have to replace 2 with a variable obtained from the user, however this did not work as i got an error saying too few arguments function but i cannot see why i am getting this.
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
float Conversion (int n, int b);
[Code] ......
View 5 Replies
View Related
Mar 27, 2013
The code should convert binary numbers to decimal but it doesn't..
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
int main()
{
[Code] ....
View 4 Replies
View Related
Nov 15, 2013
The goal of my program is to convert a decmial number to a binary number.First, the program gets an input to an array of chars, and the function translate_dec_bin converts this array to a decimal number through the strtoul function.The problem is that my program prints the binary number with an additional "0".For exmaple, for the input 1 - the program prints 01 instead of 1, for the input 3 - the program prints 011 instead of 11.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 20
void translate_dec_bin(char s[]){
char st[sizeof(unsigned)*20] = { 0 };
}
[code]....
View 2 Replies
View Related
Feb 25, 2013
I'm trying to write a program that converts a decimal number to a binary one. I have most of the program written, but I am having a little bit of trouble. Whenever I enter a decimal number, the program will convert it correctly to binary, however, the last number is not included in the conversion. EX: Converting 37 into binary (0100101) yields 010010 when entered into the program. BTW the program must utilize recursion to achieve this goal.
#include <iostream>
using namespace std;
void decToBinary(int num1);
int main() {
int num1;
[code]....
View 4 Replies
View Related
Apr 25, 2014
This is the question: [URL] .....
Now I have the binary numbers printed out in my code, but I don't know how I can covert them into to decimal.
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main() {
int numberOfDigits;
int numberOfRows;
char flag;
[Code] ....
View 1 Replies
View Related
Jul 11, 2014
What is the difference between the two functions below? I created the function in the top and my friend created the function in the bottom. I just want to know why the function with the while loop prints the binary numbers backwards. And the recursive function prints the binary numbers correctly.
void findBinary(int num) {
int remainder = 0;
while ( num > 0) {
remainder = num % 2;
cout << remainder;
num = num / 2;
[Code] .....
View 3 Replies
View Related
Jun 22, 2013
I am learning c because I want to get back into programming microcontrollers, which I previously did in assembly. I wanted to make something fairly tight in terms of program memory and RAM to show me an output in binary form. When you are troubleshooting a file register or serial interface when you can see the actual bit values (on a small LCD for a micro-controller) and compare it to a datasheet.
Code:
#include <stdio.h>
#include <math.h>
int main() {
int i;
int decimaltoconvert;
int convertingarray[7];
int convertingarray2[7];
[Code] .....
Also, how might I go about putting that into a function that I could call?
View 6 Replies
View Related
Oct 9, 2014
My size of binary file is 1920 KB and my struct size is 124 kb. now to find number of records in file I divided 1920/124 and it gives me 15.4.... do I add 1 to 15.4 and make it 16 or do i take it as 15?
View 9 Replies
View Related
Apr 16, 2014
I want to convert a decimal number to binary and store it in a string so that I can use that binary output for later computation. Here is what I did
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
[Code] ....
Now as you can see that all the binary output is in a[] but how do I get it into a string so that I can use something like printf("%s",string) and get the binary output ?
View 7 Replies
View Related