C++ ::  Binary Program / How To Eliminate Leading Zeroes Of Input

Nov 18, 2013

I am looking to eliminate the leading zeroes of the input. The format has to stay the same and output must be as hinted in formatting.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
void process(ifstream& infile, char&ch, int&dec, int&c, int&w);
int main(){

[code]....

View 2 Replies


ADVERTISEMENT

C++ :: Padding Zeroes Onto A Binary Number

Feb 24, 2014

The following piece of code is supposed to output the binary representation of a given integer and it does exactly that. However, if the given integer is 2, then output is 01. Is there a way to make the program output 0001. I am working on a C program that outputs 4-bit gray code.

#include <stdio.h>
#include <math.h>
int main(void) {
long int n=2;
while (n) {
if (n & 1)
printf("1");

[Code] ......

View 2 Replies View Related

C++ :: Creating Binary Tree Program - Allow User To Input Data Types

Apr 23, 2013

In class we were asked to create a C++ BTree program that would allow a user to input the following data types and then store said data in a .txt file:

0. ID 8 bytes

1. First name 30 char

2. Last Name 30 char

3. Street Address one 30 char

4. Street Adress two 30 char

5. City 30 char

6. State 20 char

7. Zip 10 char

8. Country 30 char

(I'm not particularly asking for full code, pseudo code would also be great). I had a great deal of my work done, unfortunately, the computer I was working on crashed, corrupting my files.

View 4 Replies View Related

C :: Eliminate Use Of Sin Function

Apr 28, 2014

so i got a project from my college to make a calculator including numerous things. everything was done but at the last moment my teacher refused the use of sin() function and asked us to make it manually and not use the sin() function. creating the new code. with a deadline of less than 24 hours. here is the part of code that needs the change, we need to eliminate the use of sin() function.

r=n1*(M_PI/180);
v= sin(r);
printf("%f",v);

View 13 Replies View Related

C++ :: How To Cut Off Zeroes From Double Datatype

Nov 30, 2014

I just wanted to know a way to cut off any remaining zeroes from a double data type. I' trying to calculate cost and output it but it keeps adding a bunch of zeroes on the end. I know there must be a way to

View 1 Replies View Related

C/C++ :: How To Eliminate Initial Nulls From Numbers

Dec 13, 2014

I have a semi-working program for doing this task. Here it is:

char c = 0, flag = 0, c_ = 0;
while ((c = getchar()) != '.') {
if ((c >= '0'&& c <= '9') && (c_ <'0' || c_ >'9')) {
if (c == '0')
flag = 1;
} else putchar(c);

[code].....

But when I enter "000000a123000500" the program returns "0a23000500" instead of "0a123000500". Please change my program to have it do what it need to or give me some hint. Using getchar and putchar only! No massives and pointers!

View 1 Replies View Related

C :: Create Two Dimensional Array That Displays Zeroes In 10 By 10 Format

Mar 24, 2013

I'm trying to create a two dimensional array that displays zeroes in a 10 by 10 format. But I don't really know how.I've been playing around and this is what I have so far:

Code:

#include<stdio.h>
int main(void) {
int my_array[10][10]={0};
int i,j;

[code]....

View 6 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++ :: Getline Out Of Stringstream Should Not Cut Leading Whitespace

Jul 1, 2013

I have a std::stringstream sstr I read data from with getline(sstr, s, ',').

Now I don't want it to cut off the leading blanks. How can I do that?

View 2 Replies View Related

C/C++ :: Remove Leading Zeros Of Numbers

Mar 8, 2014

I am trying to remove the leading zeros of the number user enters so 000002 will turn into 2. However, I am getting an error saying Segmentation fault (core dumped)

#include <stdio.h>
#include <string.h>
int main(){
char *str;
scanf("%c", *str);

[Code] ....

View 1 Replies View Related

C++ :: Leading Underscore Reserved For Implementation

Feb 6, 2012

I've always been bothered when people say "don't name your variables with a leading underscore, it is reserved by the implementation", so I decided to ask this once and for all.

The actual standard says:

17.6.4.3.2 Global names [global.names]

1 Certain sets of names and function signatures are always reserved to the implementation:

- Each name that contains a double underscore _ _ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
- Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

Unless I'm mistaken I read this as:

Words like "__foo" or "_BAR" are strictly off limits, as the implementation may have used it as a macro.Words like "_foo", when used for things such a member variables, or scoped variables on the stack are fine. The implementation only gets to use those as global functions inside mainspace.

So my question is this: While using leading underscores is generally frowned upon, is it, strictly according to the standard, wrong?

View 5 Replies View Related

C++ :: Display Actual Number Without Leading Zeros

Jan 20, 2014

With the loop below, is there a way to display the actual number without the leading zeros (scientific notation) or will it just display 0 since there are so many leading zeros?

num = 1;
while (num > 0){
num /= 2;
}
cout << num;

View 6 Replies View Related

C Sharp :: String Format Removing Leading Digits

May 7, 2014

In formatting strings, how would I only get the decimals?

So, 1.456 would be .456(no digit before the decimal). I have seen a lot on removing the decimals or rounding to a certain place.

View 1 Replies View Related

C++ :: Eliminate Comma And Split String Into Individual String Variables

Nov 15, 2013

I have this string d ="3 J JD, K" and i want to split the string to individual string. I have this code which eliminates the comma but doesn't split the string into individual string.

#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
string str = "3 J JD,K";
stringstream ss(str);

[Code] ....

Output of the code is
3 J JD
k

but I want
3
J
JD
K

Also after I split the string is there any way to put the split string into individual string variables.

View 9 Replies View Related

C++ :: How To Take Binary Number As Input

May 31, 2013

how to take binary number as an input, generate partial products by bit-wise multiplication and in last step to add all the partial products to generate final products".

View 5 Replies View Related

C :: Simple Decimal Input To Binary Output

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

C :: Use Main Function To Ask For Input To Convert Hexadecimal To Binary

Mar 15, 2013

Code:

#include<stdio.h>#define MAX 1000
int main(){
char binaryNumber[MAX],hexaDecimal[MAX];
long int i=0;
printf("Enter any hexadecimal number: ");
scanf("%s",hexaDecimal);

[Code]...

So this is my current code, is there anyway I can reduce the size and use a main function to ask for input and a call function to do all the conversion and return it? I am confused for the past few days trying to figure it out and finally ended up here. Anyway can I write it as a something like this

Code:

int main()
{
//ask for user input hexadecimal into here and call a let's say hex2binary() function
}

int hex2binary(...)
{
//an array with dynamic memory, malloc? and convert it and return values
}

I don't really need the full code, just a simple instruction on how and where to start.

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++ :: 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

C :: Binary Search Program Using Graphics

Nov 22, 2013

Looking for the binary search program using c Graphics....

View 5 Replies View Related

C/C++ :: Binary And Linear Search Program

Mar 30, 2014

// ***This program uses a binary search and a linear search to see if a 3-digit lottery number matches the number on any of the player's tickets.***//

#include <iostream>
using namespace std;

[Code].....

bunch of errors and completely lost. what it's supposed to look like.

View 4 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/C++ :: Program To Print Out Binary Value Of 16 Bit Number

Sep 22, 2013

Write a program to print out the binary value of a 16 bit number.

Create integers i, count, and mask.

Set 'i' to a hex value of 0x1b53.

Set mask to a value of 0x8000. Why?

print a line to show the hex value of i and then the leader for the binary value like this: Hex value = 1b53 Binary=

Use a for loop to loop 16 times and print 16 digits, using count as the loop counter

To test for each digit value, bitwise and 'i' with 'mask'

when the result for the bitwise and is true, print the number '1'

when the result for the bitwise and is false, print the number '0'

then shift mask one place to the right

print a new line and then quit

Use prtscrn and make a hard copy of the code with the console output.

Extra: use the modulus of count and print a space after every 4th digit to make the binary easier to read

The output should look like this: Hex value = 1b53, Binary= 0001 1011 0101 0011

so far this is what i have

#include <stdio.h>
#include <stdlib.h>  
int main() {
    int i, count, mask;
    //   1B53  0001 1011 0101 0011
    //   8000  1000 0000 0000 0000
    i = 0x1b53;

[Code] ....

it is telling me that there is an "else" without previous "if", also is the program that I wrote correct?

View 3 Replies View Related

C :: Guessing Game Program - Binary Search

Apr 5, 2014

I'm playing with a guessing game program as a personal exercise, but I'm missing a vital piece - the binary search-style code.

"Have the program initially guess 50, and have it ask the user whether the guess is high, low, or correct. If, say, the guess is low, have the next guess be halfway between 50 and 100, that is, 75. If that guess is high, let the next guess be halfway between 75 and 50, and so on."

(We're assuming that the user won't cheat.) I need the average, essentially. As in, (50 + 75) / 2 = 63.. but when I use this method of "guess = (high+low)/2, it just keeps giving me 50. I can't remember what operators I should use to increment the program's response based on the user's input. It's literally a binary search, that needs to go where those TODOs are. If low was chosen, it would have to start by being at least 51, to 100, so I'd have to set that, then find the average.

Code:
#include <stdio.h> Code: #include <ctype.h>
int main(int argc, const char * argv[]) {
int low;
int high;
int guess;
int response;
int toupper ( int );

[Code] ....

View 2 Replies View Related

C++ :: Program That Reads In A Sequence Of Binary Digits?

May 11, 2013

c++ program that reads in a sequence of binary digits (values 0 and 1) and stores them into a STL container. The input should terminate on any input that is not a 0 or 1. After finishing the read-process, apply a "bit-stuffing" algorithm to the container. In this case the bit stuffing should occur after four consecutive bits of the same value.i,e. four 0's or four 1's.. Also write the de-stuffing code to process the stuffed data to recreate the original data and verify that the original data is recovered correctly.

View 6 Replies View Related

C++ :: Program Crash Writing To Binary File

Feb 17, 2014

cant write to binary file

#include <stdio.h>
#include <stdlib.h>
typedef struct {
int number;
} something;
void main() {
int numbers[10]={1,2,3,4,5,6,7,8,10,12};

[Code] .....

View 2 Replies View Related







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