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


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 :: 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++ :: 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 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++ :: Checking To See If Integer Is A Character

Feb 14, 2014

#include <iostream>
using namespace std;
int main(){
int x;
cout << "Enter character:";
cin >> x;

[Code] ....

If i type in:
+
How come it says that "this is not addition?

View 5 Replies View Related

C++ :: How To Convert Character To Integer

Mar 15, 2012

This is my c++ code...the problem is the RESULT is not coming and a bigger number is outputting...I dont know how to convert character to integer..

Code:
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
const int size = 50;
char infix[size],postfix[size],stack[size],dummy='?';
int top=-1;

[Code]....

View 7 Replies View Related

C :: How To Read In A Character Followed By Integer Without Space

Feb 13, 2014

how to carry out the conversions. The assignment is the normal hex to octal and Quart (base 4) via bit munipulation which I have worked out myself. However, I have been trying all day to figure out how to read in a string such as H1234, or O4567. How to parse the input I can handle the remainder myself. I'm just stuck and I've tried for hours.

View 5 Replies View Related

C++ :: Swap Values Of Integer And A Character

Oct 31, 2013

Im trying to swap the values of an integer and a character, however Im not sure where to insert the static_cast<type> part that I need for this to happen?

// Program to demonstrate a function template
#include <iostream>
using namespace std;
// Interchanges the values of variable1 and variable2
template<class T>
void swap_values(T& variable1, T& variable2)

[Code] ....

View 5 Replies View Related

C++ :: Convert From Integer To Character String

Oct 2, 2013

I have been trying to write a function which can convert a number from an unsigned long integer to a readable ASCII character string. this is what I have come up with, but I am receiving some very strange characters in return. Could the problem be that I am telling a char to = an unsigned long int, (cString[i] = product[i])?

void convertToString(unsigned long con) {
unsigned long product[10];
char cString[10];
const unsigned long begConvert = 10 ^ 10;

[Code] ....

View 4 Replies View Related

C++ :: Passing / Returning Character And Integer Arrays With Functions

Jun 21, 2013

Passing and returning character and integer arrays with functions using simple programs...use pointers if necessary

View 1 Replies View Related

C/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer

Feb 11, 2014

The function uses a "for" loop to print the given character the number of times specified by the integer.

How can I make a for loop to do that?

So.. my code looks like this:

// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {

[Code] ....

So.. here is my error:

Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6

View 3 Replies View Related

C++ :: Universal Order / Spacing Of Character Encoding For Integer Digits?

Feb 7, 2012

I have a char *pch that points to an integer digit 1 or 2 or ... 9. To get the character that's 1 less, instead of converting to int, minus 1, then converting back to char, I tried (*pch -1) and that seemed to work. I suppose that's because the particular character encoding on my system is such that the digits are encoded in the same order and spacing as the integers they represent. So the question is does this "convenience" feature hold true for all character encoding systems?

View 10 Replies View Related

C/C++ :: Binary Tree - Count How Often Character (e) Appears In It

Feb 5, 2015

I have a binary Tree and I have to count how often the character 'e' appears in it. Then I have to print it Inorder.

My code:

#include<stdio.h>
#include<stdlib.h>
struct node {
struct node *left;
struct node *right;
char chr;

[Code] ....

But I always get the Error Message "expected ';' ',' '.' or ')' befor numeric constant in this line:

struct node *mkNode(char chr, struct node *1, struct node *r)

View 1 Replies View Related

Visual C++ :: Prompt User To Enter Integer Value And Character Code To Indicate Conversion

Sep 14, 2013

I'm expected to write a c program for this question :

Using these header files
#include <stdio.h>
#include <conio.h>

Question : Write a program that will prompt the user to enter an integer value and a character code to indicate whether they want to do a Kilogram to Pounds conversion (A) or a Pounds to Kilogram (B) conversion. Note that 1 kg = 2.2 pounds. The program should then do the necessary conversion indicated by the code and display the newly converted value to the screen.

View 1 Replies View Related

C++ :: Passing Fixed Character Array Into Binary File?

Apr 19, 2014

all i want to do is to read a fixed char array sized 4 from user and pass it to Binary File then Print Encrypted content from the the File to the console screen .. but it seems it prints the same input every time .. and i tried everything .. it works fine with integers and strings .. but when it come to char array nothing ..

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

[Code].....

View 6 Replies View Related

C++ :: Writing 32 Bit Integer To 32 Bit Value In Binary

Jul 17, 2013

So, I was reading that article on binary files:

Disch wrote:
u16 ReadU16(istream& file) {
u16 val;
u8 bytes[2];

file.read( (char*)bytes, 2 ); // read 2 bytes from the file
val = bytes[0] | (bytes[1] << 8); // construct the 16-bit value from those bytes

[Code] .....

u32 would be the same way, but you would break it down and reconstruct it in 4 bytes rather than 2.

But, I don't know what he means by the part in bold text.

View 8 Replies View Related

C++ :: Turn Binary File Data Into Unsigned Character Array For Inclusion In Executable

Jul 10, 2013

So I wrote a program to turn a binary file's data into an unsigned character array for inclusion in an executable. It works just super.

I'm wondering how I can write a program that will perform this operation on every file in a directory and all it's sub-directories so that I can I can include everything I need all at ounce.

View 9 Replies View Related

C++ :: Loop Conversion Integer To Binary

Aug 9, 2013

This program is basically working. I'm very knew to C++, so basically I need instructions as if you were explaining this to your grandma. I need this to loop but how to incorporate one. Basic code (while loops). Here is what I've done so far.

#include <iostream>
using namespace std;
int main () {
int i, c, k;
cout << "Please enter a number to convert: ";
cin >> i;

[Code] ....

View 4 Replies View Related

C++ :: Writing Integer Array To File In Binary Form And Reading It

May 30, 2013

Both arrays arr and pointers are the same size. I am having problems reading pointers from file into a new int array.

FILE* ky_pt=fopen("stashedclient","ab");
write(fileno(ky_pt), pointers, sizeof(pointers) );
pointerindex=lseek(fileno(ky_pt), 0, SEEK_CUR );
printf("pointerindex after writing array %d

[Code] .......

View 2 Replies View Related

C++ :: Accept Signed Decimal Integer As Input And Output In Binary

Jan 29, 2015

Write a C++ application program to accept a signed decimal integer as input and output the equivalent 2s complement version in 16-bit binary. Include a space between every four bits in the output string. The input will only be processed by the application if it falls in the valid range that can be represented in 2s complement format with 16 bits. The range of a decimal number from - to + is -32768 to 32767.

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







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