C :: Program To Convert A Number Into A More Readable Format
Oct 14, 2014
I wanted to write a program to convert a number into a more readable format. It's like, if the input enters the number as 2361263 the output should be like 2,361,263. I went about this problem like extraction the number first and then if the count was equal to multiple of three i'd print ',' instead of the number.
But initially when i wrote the code for extracting a single digit from the number
Code:
#include<stdio.h>
void main() {
unsigned long long num=pow(2,50);
int count=0;
while(num!=0) {
int last_digit;
[Code]....
I know that I'd lose the number when i finish printing it, but still I only end up printing the entire number in reverse order.
As in if the input is 1234 the output is 4,321 which is not what i want.
One way of overcoming this problem is to store the values in an array and then reading then back from the end. But i wanted to know if there is a better solution than this? To extract the digits from the number in the same order as it is in the number
View 5 Replies
ADVERTISEMENT
Oct 4, 2014
Is my understanding correct?
Ascii 'a' = 61 (Hex)
Ascii '0' = 30 (Hex)
So this is how we convert characters to hex.
Integer 0 = 0 (Hex), because it's not a character but an integer.
View 8 Replies
View Related
Apr 25, 2013
a few pointers in building an assembler in C for a 68hc11 micro controller I'm struggling on a way to convert the assembly language in a txt file to s19 format.
View 1 Replies
View Related
Jun 13, 2013
I have total time in seconds (say 2500 seconds). I want to store this time in CTime or CTimeSpan format.?
How to do this.?
View 2 Replies
View Related
Mar 27, 2013
I nead to write a program that convert an octal number to decimal number, I thought I did it right but it doesn't work.. I have to use in the first for loop as it is because it is part of the instructions (student homework).
#include <iostream>
#include <math.h>
using namespace std;
void main() {
double numOfDig, num, newNum;
[Code] ....
View 1 Replies
View Related
Jun 8, 2013
How do I convert date in integer format to DateTime without using DateTime?
I have tried:
Regex regex = new Regex(@"^(0[1-9]|1[012])(0[0-9]|1[0-9]|2[0-9]|3[01])(1[789]|[2-9][0-9])dd+$");
if (regex.IsMatch(txt_fromdate.Text) == true)
{
DateTime dt = DateTime.ParseExact(txt_fromdate.Text, "MMddyyyy", null);
}
View 1 Replies
View Related
Feb 22, 2015
My problem is that the setfill('0') doesn't affect the output; I want four columns of 64bit numbers in hex which I read in binary mode from a file.
Here is the problem:
fffffff2 f1040000 fff10000 780000
76000d 11740000 0 5f
5f40405f 50636853 796d5f40 30304055
66687669 68556867 76657655 776c7866
and the code to produce it:
cout << hex << setw(4) << setfill('0') ;
unsigned long test,inc,grp;
grp = 0;
for (int i = 0; i < size; i += 4){
test = buffer[i];
[Code] .....
View 6 Replies
View Related
Jun 23, 2014
I'm currently trying to create binary file will not be able to be read as texts and will contain metadata(more like image files).
But I've tried writing to .dat, .bin files in binary mode and all of them are displaying in ascii text..which I don't want.
View 3 Replies
View Related
Jan 19, 2014
I have almost a hundred names in a text file that I want to convert to email addresses and save to another file. I seem to have it working, but it doesn't print the full names in the email prefix. The output I'm looking for is Doe_John@livebrandm, but I'm only getting D_J@livebrandm. I'm not sure what I should specifically be reading up on that applies to this directly.
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
FILE *fpin=fopen("namesIN.txt", "r");
FILE *fpout=fopen("emailOUT.txt", "a");
char first[20],last[20],inbuff[1500];
[Code]...
View 9 Replies
View Related
Feb 16, 2014
Suppose i have a very large number stored as a string, say
std::string str = "1000000000000000000000000000000000001";
And i use std::stringstream to convert it to int like this
std::stringstream ss(str);
uint64_t i;
ss >> i;
Then I would be maxed out right. so how would one practically handle things like comparison of two such numbers.
I could think of 2 approaches :
1) I can compare the numbers character by character.
2) I can put the results of ss >> i; into an array then compare each element of array
would there be any other methods??
View 4 Replies
View Related
Dec 4, 2014
I don't know how to ask the user to enter the date in this format (DD/MM/YY) and ISBN number with hyphens.
After user enter date and ISBN number, it should look like this:
Date: 5/24/12
ISBN: 0-000-12345-0
#include <iostream>
#include <string>
using namespace std;
int main() {
string date;//MM/DD/YY Format
[Code] ....
View 7 Replies
View Related
Jun 8, 2014
heres the function:
string ToString ( const char * format, ... )
{
char buffer[256];
[Code]....
these function do the same of the sprintf() function. but instead we use a variable for add the result, i want to return the result. when i use it:
string f;
f=ToString("hello world");
gives me several errors:
"error: crosses initialization of 'std::string f'"
"error: jump to case label [-fpermissive]"
View 7 Replies
View Related
Jul 6, 2013
Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.
Sample Output 1:
8-bit Binary Number => 11111111
Decimal Number = 255
Sample Output 2:
8-bit Binary Number => 10101010
Decimal Number = 170
Sample Output 3:
8-bit Binary Number => 101010102
Number entered is not a binary number
#include <iostream>
using namespace std;
int main()
{
int num;
[code]....
View 2 Replies
View Related
Jul 5, 2013
Here's the part of the codes where I tried to use boolean expression:
Code:
#include <iostream>
using namespace std;
int main() {
int num;
cout << "8-bit Binary Number=";
cin >> num;
[Code] .....
How can I get started with the body?
View 7 Replies
View Related
Jul 5, 2013
Here's the part of the codes where I tried to use boolean expression:
#include <iostream>
using namespace std;
int main()
[Code].....
May I know that how can I get started with the body?
View 5 Replies
View Related
Apr 2, 2013
I want to create a program where you enter today's date, in the following format: 02/04/2013. As well as your birth date in the following format: 27/09/1994. After doing that I want to assign the day, month and year of the present date, as well as the day, month and year of the birth date in to their own variables (for example, Day, Month, Year), and then calculate your age.
I have tried doing this with cin.get(), but this method is way too long, and I'm looking for a shorter method
View 2 Replies
View Related
May 15, 2013
I want to convert image to number.
View 12 Replies
View Related
Mar 6, 2015
How to convert e.g. number 75 to base 4 representation? The result should be 1023. I plan to use uint32_t
x = a3.43 + a2.42 + a1.41 + a0.40 = a3.64 + a2.16 + a1.4 + a0
View 9 Replies
View Related
Dec 7, 2014
I had an exercise that required me to convert a number to binary (base 2) which as simple enough.
Code:
#include <iostream>#include <iomanip>
#include <cmath>
using namespace std;
void Conversion (int n);
int main () {
[Code] .....
I now have a follow on exercise that requires me to convert to binary from ant base up to 10, i thought this would just be replacing the 2 with a variable obtained form the user, but i am having problems as within the function i am getting an error that i haven't passed enough arguments and i cant see why i get this. I did the following:
Code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
float Conversion (int n, int b);
[Code] ....
View 2 Replies
View Related
Aug 19, 2014
How do you convert a number float in a range of -10.0f to 17.0f to a eqivalent number in the range of 0.0f to 1.0f?The code does not work well. floaty is the float to change.
//change range to 0..1
diamond[x][y] = (floaty - minY) / (maxY - minY);
View 19 Replies
View Related
Dec 6, 2013
I receive a negative number but in big endian order. ntohl seems work for unsigned only.
Is there a method for me to translate it back to the original negative number from big endian?
View 2 Replies
View Related
Sep 17, 2014
#include "stdio.h"
#include <stdarg.h>
#include <math.h>
// Main Function
int main(void){
int number;
printf(" Please enter a number from 1-10? ");
scanf("%d", &number);
[Code] ....
I took the while statement out didn't want that in there.
View 2 Replies
View Related
Oct 12, 2013
i want to convert the Digits in words.I have already a code but in my code the value is coming like for ex:-540000(Five hundered and Fourty Thousand ).but i want Five Lakh and Fourty thousand.
View 4 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
Feb 26, 2013
I'm trying to pass a decimal number to a function and convert it to binary and return it and print it out in main. But it prints out 1011 and then seg faults...not sure where it's tripping up
Code: int main(){
char* binNum = decToBin(25);
int i = 0;
while(binNum != NULL){
[Code].....
View 6 Replies
View Related
Sep 9, 2014
What I'm trying to do is have the user input a hex number this number will then be converted to a char and displayed to the monitor this will continue until an EOF is encountered.I have the opposite of this code done which converts a char to a hex number. The problem I'm running into is how do i get a hex number from the user I used getchar() for the char2hex program. Is there any similar function for hex numbers?
this is the code for the char2hex program
#include <stdio.h>
int main(void) {
char myChar;
int counter = 0;
while(EOF != (myChar = getchar())) {
if (myChar == '')
[Code] .....
This is what i want to the program to do except it would do this continuously
#include<stdio.h>
int main() {
char myChar;
printf("Enter any hex number: ");
scanf("%x",&myChar);
printf("Equivalent Char is: %c",myChar);
system("pause");
return 0;
}
View 1 Replies
View Related