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


ADVERTISEMENT

C :: Float / Integer Conversion

Oct 14, 2013

why does the following code output "0.000000" instead of "1.000000"?

Code:

#include <stdio.h>
int main(void) {
int x=3, y=2;
printf("3/2 is %f
", x/y);
return 0;
}

the code was compiled and run using gcc 4.4.7 and glibc 2.17 on linux kernal 2.6.32 running on a PC with an intel i5-2500k cpu(sandy bridge)

View 8 Replies View Related

C Sharp :: Integer To Boolean Conversion?

Nov 20, 2014

ive written a simple code but throws an error in C#, why is this happen.

    bool inputValue = Convert.ToBoolean(Console.ReadLine());
        Console.WriteLine(inputvalue);
        Console.ReadLine();

View 3 Replies View Related

C :: Wrong Result In Integer Conversion To Little Endian

Feb 18, 2015

I am trying to convert uint32_t or unit16_t to chars in little endian. When I was reading the char s from binary file I used memcpy so I did not need to convert them, but now I try this:

Code:

static void write2Bytes(unsigned char ** pDestStr, uint16_t* item) {
(*pDestStr)[0] = ((uint16_t) item & 0x00ff);
(*pDestStr)[1] = ((uint16_t) item & 0xff00) >> 8;
*pDestStr+=2;


[code]...

In the last function I try either to cast to uint_32_t or unsigned char but in both case I got wrong values. The original binary string read from left: 0x36000003 (it is number corresponding to 48Mbytes).

And the result when casting to unsigned char is T000000 and T(>00 for uint_32. So what's wrong? I need to get some string with will be corresponding to 0x36000003. does this kind of convertion take a lot of compute performance when I one would use it offten (like when one would do convesions for bitmaps).

View 7 Replies View Related

C/C++ :: IP Address To Binary Conversion

Mar 10, 2014

Converting an IP address to a binary number? As in the entire thing 123.45.555.49 to it's binary equivalent.

View 14 Replies View Related

C++ :: Binary To Decimal Conversion Program

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

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++ :: Generating Conversion Table For Wrench Sizes - For Loop

Feb 15, 2014

I'm writing a program where I need to generate a conversion table for wrench sizes with the following columns: Size (Inches) [Fraction], Size (Inches) [Decimal rounded to 3], Next Bigger Metric (mm), Difference (Inches) [Next Bigger Metric-Inches], Closest Metric (mm) [to original size], and Difference (Inches) [Closest Metric-Inches]. I've created the column for the Size in fraction form relatively quickly but I cant seem to produce the decimal version. Instead, I get 0.000.

Code:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
using namespace std;

[Code] ....

View 4 Replies View Related

C :: Binary To Decimal Conversion Through A Port To Display On LCD Display

Dec 6, 2013

I know this is more simple than I am making it out to be. I have a solar panel hooked up to an 8-Bit ADC and linked into my Microprocessor. I am trying to take the Binary readout from the ADC and convert it to a decimal number to be displayed on the boards LCD display. I am wiring the ADC to PORTA on my Motorola Freescale Board. This is for a final project for my electronic systems class due on Monday...

View 3 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 :: 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++ :: How To Trap Integer Inputs Using While Loop

Sep 30, 2014

This is just a portion of my program and I want to trap the integer inputs using while loop.

cout<<"
Enter the name : ";
while(/*integer input or not in character*/) {
//Invalid Input!
}
cin.ignore();
cin.getline(name, 100);

View 1 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++ :: Finding The Largest And Smallest Integer In A Set Using While Loop

Sep 29, 2014

I've been working at this for awhile and it seems like it should be correct but it isn't giving me the desired output. Here's my code.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>

[Code]....

And here is my output when I run the program.
75
Max: 90
Min: 0

Press any key to continue . . I am reading from a file in this program which contains a set of 30 numbers and it has the average correct and the max correct but the minimum number in the set is 56 however it keeps giving me a zero for the min.

View 4 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/C++ :: Creating A Binary Search Loop?

Oct 13, 2014

I am creating a binary search program that lets the user input up to 10 integers and then the program displays the array and sorts it. When the user is prompted to select an integer, if the integer is in the array, the program responds with the array subscript part. I can get the loop to work once and maximum twice, but then it wont search for the array or say value not found even though the number in in the array. I tried making the values NULL but that only lets me go through it one more time.

Here is my code:

#include <iostream>
using namespace std;
//Functions
void printArray(int);
void selection(int);
int binarySearch(int,int,int);

[code]....

View 6 Replies View Related

C :: Assign Integer Value To Unsigned Char Array But It Is Not Storing Integer Values

Oct 25, 2013

I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet

Code: uchar uc[100];
for(i=0;i<100;i++)
{
uc[i] = i;
}

The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.

View 9 Replies View Related

C++ :: Changing Integer Into New Integer With Simple Mathematical Operations?

Jun 15, 2014

changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).

View 4 Replies View Related

C/C++ :: Converting 8-byte Integer To String Based Integer

Oct 15, 2014

Complete the function myitohex so that its converts 8-byte integer to string based hexadecimals.

Ex: printf("0x%s",myitohex(64,hex)); should printout "0x40" on the screen
char *myitohex(uint8_t i, char *result){
???
return result;
}

I wrote:

#include <stdio.h>
#include <stdint.h>
char *myitohex(uint8_t i, char *result){
*result = i + '0';

[Code] ....

0xp gets printed out which is wrong. I think *result = i + '0'; is wrong. What changes should i do on this row ?

View 4 Replies View Related

C++ :: Zip To City Conversion

Apr 9, 2014

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

int displayMenu ();
void addRecords ();
void zip ();
void city ();

[Code] ...

View 11 Replies View Related

C/C++ :: Time Conversion Between EST And UTC

Apr 1, 2013

I want to convert time from est to utc. Is there any function for this.

View 3 Replies View Related

C++ :: 32 / 64 / 80 Bit Float Conversion?

Feb 14, 2012

I am looking for a math/big num library, that allows me to convert 32/64/80 bot float numbers to string and vice versa.

Precision & accuracy is of importance here, and since this is an IEEE standard, i have high hopes that there are libraries for this out there, which would save me the hassle of trying to implement this myself...

View 1 Replies View Related

C :: Lowercase / Uppercase Conversion

Oct 15, 2014

I am having trouble in creating a program (named "up.c") that should do the following:

- if you run the command ("up") with no arguments, it should read input from stdin and display it on stdout, converting lowercase letters to uppercase.

- if you run the command with one or more files (as arguments to the "up" command), your program should read input from each file and display it on stdout, again converting lowercase letters to uppercase.

I'm trying to create a single program that can do both of these, and handle errors gracefully. I've found that some codes work to convert the letters, but they seem overly simple and aren't giving me what I'm looking for in my program.

View 2 Replies View Related

C++ :: Conversion From PDF To Text File

Feb 25, 2013

I have this project, How do I ever Convert a .Pdf file to .txt file using C++.

View 5 Replies View Related

C/C++ :: Number Conversion To String

May 22, 2014

I'm writing a small pice of code that takes numbers and convert it to string. So that's what I got

int main() {
char letter;
char letter1;
char letter2;
cin >> letter;
cin >>letter1;
int sum = letter * 128 + letter1;

[Code] ....

Then it asks the user to enter a letter, say 'w' , which it's value is 119

Then enter another letter, say 'o' which value is 111

then it do the equation, which is take the value of the first letter multiple it by 128 then add it to the value of the second letter.

How can I make it does this process in a For loop, or any kind of loop??

Then I have the second part which is the other way around. That is when the user enter a numbers then the code convert these numbers to a string.

251394404 - "d"
1964018 - "rd"
15343 - "ord"
119 - "word"

so what's happening here is the it divide each time by 128. But I can't do that in a code.

View 3 Replies View Related







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