C++ :: Binary To Grey Code Converter?

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


ADVERTISEMENT

C :: Binary To Decimal Converter

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

C++ ::  Binary To Decimal Converter

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

C :: Integer / Character Converter To Binary

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

C :: Decimal To Binary Converter (8-bits)

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

C/C++ :: Number To Binary Converter Program?

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

C++ :: Bloated Binary To Decimal Converter?

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

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 View Related

C :: How To Strip A Code To Binary

Aug 25, 2014

I am using windows 64 bit 2007 , codeblocks and ive tried googling on how to strip all symbols to binary so that the people i send it to cannot read the game files but ive not found anything much... How do i do it on codeblocks..? Code:

View 4 Replies View Related

C/C++ :: Code To Open Binary / Raw Video File

Oct 9, 2013

I am working on H.264 encoder. How to open a binary file using c, i have tried and have got zero errors but end result its not opening....

View 3 Replies View Related

C/C++ :: Compiling Source Code And Making Binary File

Apr 19, 2014

How to compile this source code and make a binary file

I think this need linux and run make command or gcc

This binary is a super user for android

source code attached

Attached File(s) : su.zip (7.59K)

View 3 Replies View Related

C :: Fahrenheit And Celsius Converter?

Feb 5, 2013

I know my current program will not compile. How can I store the the start temperature so it can be used again in the final printf statement "start degrees Fahrenheit is converted Celsius."?

Note - I want to use the float data type for precision.

Code:

//THIS PROGRAM WILL CONVERT TEMPERATURES BETWEEN DEGREES FAHRENHEIT AND DEGREES CELSIUS
#include <stdio.h>
int main(void)

[Code].....

View 4 Replies View Related

C/C++ :: Roman Numeral Converter?

Dec 23, 2013

I am writing a program that converts arabic numbers into roman numerals.

Quote Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement to display the Roman numeral version of that number.

Input Validation: Do not accept a number less than 1 or greater than 10.

Prompts And Output Labels. Use the following prompt for input: "Enter a number (1 - 10): ". The output of the program should be of the form "The Roman numeral version of A is R" where A is the Arabic numeral entered (1,2,3,...) and R is the all-capitals form of a Roman numeral, such as VII.

View 14 Replies View Related

C :: Fahrenheit To Celsius Scale Converter

May 28, 2014

One of the questions requires writing up a code, that converts Fahrenheit scale to Celsius scale.

The relation between temperature in ◦ C and ◦F is given by the formula:

◦C = 5/9 . ( ◦F - 32 )

Write a program that prints a table (just two columns without any borders) with temperature in ◦F and ◦C for temperatures between 0 and 300 ◦F in steps of 20◦. Compile and run your program. I wanted to approach this problem via arrays and for loops, and I wrote up this

Code:
#include<stdlib.h>
#include<stdio.h>
int main() {
// begin main()
// units
double[] celsius = new double[ 16 ];
double[] fahrenheit = new double[ 16 ];

[Code] ....

Now when I'm trying to compile that, the compailer throws an error which makes absolutely no sense to me.

Code:
fahrenheitCelsius.c: In function ‘main’:
fahrenheitCelsius.c:18:9: error: expected identifier or ‘(’ before ‘[’ token
double[] celsius = new double[ 16 ];

[Code] ....

View 7 Replies View Related

C# :: Font Converter Style Parameter?

Sep 1, 2014

I need to convert a string into a Font object. I'm trying to use the Font Converter but I don't see support for the font Style. I need to save a font to a string and back again using the font name, size and style.

Font font1 = (Font) converter.ConvertFromString("Arial, 12pt");

View 1 Replies View Related

C/C++ :: Grade Converter Using Parallel Arrays

Apr 8, 2015

I am attempting to reconfigure a working code that before used while loops and if statements to convert a numeric score to a letter grade. I now wish to take this same code however I want to change the char convertGrade(int numScore) to simply use a parallel array as a replacement to the if statements.

The array needs to consist of 3 arrays of fixed size 5:
int minScores[SIZE]
int maxScores[SIZE]
char letterGrade[SIZE]

I know the declarations need to go in the function convertGrade but this is the first time I have worked with arrays and I am having trouble trying to figure out how this array will replace my previous if statement.

In order to access the array elements I need to write specifications such as
minScores[i]
maxScores[i]
letterGrade[i]

(where i = 0, 1, 2, 3, or 4)

#include <stdio.h>
#include <stdlib.h>
#define SIZE 5
int getScore(void);
char convertGrade(int numScore);

[Code] .....

View 5 Replies View Related

C++ :: Temperature Converter From Imperial To Metric - For Loop

Nov 26, 2013

I've been doing some practice programming challenges and I am currently making a temperature converter from Imperial to Metric.

My approach was to make it as simple as possible but it must display correctly and use decent I/O manipulations corresponding with how high the counter is.

This is what I have come up with, and everything seems to work fine for a base where I could possibly add more code to include user input, but before I go to that one step further I'd just like to know if the approaches I have taken to using iomanip is OK practice and I haven't done any serious no-nos, as I haven't seen any code from example videos that people make that includes this!

Here's the code:

#include <iostream>
#include <iomanip>
using namespace std;
int main()

[Code] ....

The reason I added the IO manipulators is because I couldn't stand seeing everything not lining up, it looked very sloppy and unprofessional..

View 2 Replies View Related

C++ :: Create A Converter But Results Must Be In 4 Decimal Places

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

C++ :: Temperature Converter With A Menu - Printing Right Output

Nov 13, 2014

I'm trying to make a simple temperature converter with a menu that lets users pick which conversion to perform. But, it won't seem to print the right conversion. It just prints the same temperature that I inputted.

for example:

#include <iostream>
using namespace std;
//prints the menu
void userMenu(){
cout << "Temperature Calculator" << endl << endl;

[Code] .....

View 2 Replies View Related

C++ :: Variable To Byte Array Converter Class?

Aug 18, 2012

I've been working on making a class that makes turning any variable or object into a byte array and vice-versa, quick with minimal pointer interface.

As well as a function for turning any variable or object into a binary text string.

Code:
#include <iostream>
#include <bitset>
#include <sstream>
// Convert a Variable to a Byte Array
template <class var>
unsigned char* VarToBytes(var &data) {

[code].....

View 2 Replies View Related

Visual C++ :: Roman Numeral Converter To Decimal Using Array Of Strings

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

C :: Print Out - Array Code And Pseudo Code?

Apr 15, 2013

I have assignment which requires me to print out and array code and a pseudo code. I dont no what a pseudo code is,.

View 2 Replies View Related

C++ :: Reducing Code Duplication From Common Code Calling Common Class

Apr 13, 2014

I have a class 'A' which is almost perfect for my needs. Class 'B' uses class 'A' I've now designed Class 'C' and Class 'D' and noticed that there is a good chunk of code in class 'B', 'C' and 'D' for using Class 'A' is duplicated. I've separated out this code in specific, standalone functions in each of the classes. Now I'm wondering where this code should go. At the moment, the functions are duplicated in the three calling classes (B, C and D). Placing the functions into class 'A' would break the single responsibility principle. Inheritance to add functionality would likely break both SRP and LSP. The one that seems that it may work is composition.

However, Is designing a complete class just for a few functions over kill?

Would it be valid for classes 'B', 'C' and 'D' to access both the new class 'E' (which would depend on A) and the old class 'A' (which would have to be the same instance as the instance in the new class 'E'), or should the new class 'E' provide sufficient functionality so that Classes B, C and D don't need to access Class A directly? It would seem that its then an incomplete interface of the original object with additional functionality (ie, incompatible) Or should I do it a completely different way?

View 4 Replies View Related

C :: Binary File Write By User Input Then Printing Binary File Data Out

Dec 6, 2013

Following is the program I wrote it basically takes 9 inputs and then save them into binary file. then print out the data stored in binary data and find inverse of it then print the inverse out. but its stuck in a loop somewhere.

Code:
#include <stdio.h>
int main() {
int a[3][3],i,j;
float determinant=0;
int x;
FILE *fp = fopen ("file.bin", "wb");

[Code] .....

View 6 Replies View Related

C :: How To Get Scan Code Of ESC Key

Sep 17, 2014

i wrote the following code :

Code:

#include<stdio.h>#include<conio.h>
#include<stdlib.h>
int a[][4] = {15,9,10,25,6,2,4,7,32,19,42,8,21,17,18,0};
void boxes();
void display();
void main()
{int ch,r=3,c=3,t;

[Code]...

not able to esc when i press esc key.how to get rid of this.

View 4 Replies View Related

C++ :: From String To A Code

Apr 17, 2013

I wanna to know how can i get a string from the user and treat it as a c++ code ..is there any way to do that ??

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved