Find Jobs
Hire Freelancers

I need a Programmer

$10-30 USD

Finalizat
Data postării: circa 3 ani în urmă

$10-30 USD

Plata la predare
Your task is to develop a C program, called ascii2bin, that reads a string of 1's and 0's as ASCII digits, and outputs the equivalent decimal number Your program must exercises the read() system call to read a single byte, at a time, from stdin validate that the read byte is appropriate for conversion, e.g., it must be either an ASCII '0' or '1' converts each byte into an integer value via a mathematical expression uses the resulting integer as part of the calcuation to determine the final number identifies the end of a input string by either end of file or by a new line End of file is detected when read() returns the value '0' A new line is identified in the ASCII table as either: newline, nl, LF, or \n' prints this final number on stdout returns a value of 0 upon success and 1 otherwise The Algorithm offset = ?; number = 0; retval = read(0, &ascii_value, 1); while (retval == 1) digit = ascii_value - offset; number = number << 1 + digit; retval = read(0, &ascii_value, 1); printf("%d\n", number); return 0; Validation Checks: You should add additional validation checks to your code to catch potential errors. At a minimum, validate the following: that each ASCII input character is one of the following characters: '0', '1', or '\n' that the calculated number does not exceed 2^32 I am having trouble with this program I have most of the code but my output does not match the Professors completely: #include <stdio.h> #include <unistd.h> int main() { int offset = 48; // ascii value of '0' int number = 0; char ascii_value; int retval = read(0, &ascii_value, 1); while ((retval == 1) && (ascii_value != '\n')) { int digit = ascii_value - offset; if ((digit == 1) || (digit == 0)) number = (number << 1) + digit; retval = read(0, &ascii_value, 1); } printf("%u\n", number); return 0; } These are his test file information: $ script [login to view URL] $ ascii2bin 0101 ^d 5 $ cat [login to view URL] | ./ascii2bin ; echo $? 54356 0 $ cat [login to view URL] | ./ascii2bin ; echo $? 138 0 $ cat [login to view URL] | ./ascii2bin ; echo $? 2863311530 0 $ cat [login to view URL] | ./ascii2bin ; echo $? 4294967295 0 $ cat [login to view URL] | ./ascii2bin ; echo $? 1
ID-ul proiectului: 29458100

Despre proiect

9 propuneri
Proiect la distanță
Activ: 3 ani în urmă

Vrei să câștigi bani?

Avantajele de a licita pe platforma Freelancer

Stabilește bugetul și intervalul temporal
Îți primești plata pentru serviciile prestate
Evidențiază-ți propunerea
Te înregistrezi și licitezi gratuit pentru proiecte
Acordat utilizatorului:
Avatarul utilizatorului
I already did it. It works fine. Let me know if you need any help. Proposed code is below. I can swap out that "switch" for a simpler "if" statement if you like. #include <stdio.h> #include <unistd.h> int main() { int offset = 48; // ascii value of '0' int number = 0; char ascii_value; int digit; int retval; retval = read(0, &ascii_value, 1); while (retval==1 && ascii_value != '\n') { switch (ascii_value) { case ('0'): //if ascii_value is 0 or 1 and number is not too big, break out of switch case ('1'): if (!(number & 0x80000000)) break; default: return 0; //return 0 upon failure } digit = ascii_value - offset; number = (number << 1) + digit; retval = read(0, &ascii_value, 1); } printf("%u\n", number); return 1; }
$10 USD în 1 zi
0,0 (0 recenzii)
0,0
0,0
9 freelanceri plasează o ofertă medie de $22 USD pentru proiect
Avatarul utilizatorului
Hi there, I went through the requirements and I would like to do this project if given the opportunity. Let me know if you are interested.
$20 USD în 1 zi
5,0 (545 recenzii)
7,2
7,2
Avatarul utilizatorului
HI..i am proficient in C/C++ programming with data structures, algorithms and can help you write the console program for reading strings of 0's and 1's and convert it to decimal.
$50 USD în 1 zi
4,9 (166 recenzii)
6,5
6,5
Avatarul utilizatorului
###### Having Teaching Experience in C, Python, Data structure, Algorithm Design and Analysis ######## Hi, Greetings. I am a computer engineer having masters in Mathematics, Computer Science and PhD in Computer Science. I have more than 10 years experience in developing algorithms of mathematical problems as well as computer related problems and their implementation using C, C++, Java, Python programming language. I am teaching online now several student on data structure and algorithm, C, C++, Java, Python programming etc. I would like to discuss in more detail with you to get your exact requirements. I am confident I can provide you efficient solution. Here I put a tentative bid amount and days that can be fixed after understanding the project details. I'm looking forward to your response. Best regards,
$20 USD în 1 zi
5,0 (35 recenzii)
4,7
4,7
Avatarul utilizatorului
Dear Sir. As an experienced algorithm expert, it is very interesting to me. I have been working on several data structure & algorithm projects such yours for over 7+ years. Since having programming contestant experience, I have powerful algorithm skills and full knowledge on several languages on such as c/c++, python, java, etc... I think i could be the right person for your project, because of my past experience and skills. I would be very appreciated if i have a chance to show you how could i help you to meet your goals. Thank you. Viktor.
$20 USD în 1 zi
4,9 (10 recenzii)
4,3
4,3
Avatarul utilizatorului
MASTERS IN COMPUTER ENGINEERING EXPERT IN C HELLO DEAR CLIENT I have gone through your project details and the work is DOABLE since its within my area of EXPERTISE.I will tackle are required guideline to deliver desired goal Please consider my bid. THANKS.
$20 USD în 1 zi
5,0 (3 recenzii)
3,5
3,5
Avatarul utilizatorului
Hi; i can help you Now (immediately) send me a message so that we can discuss more. Thanks and regards.
$10 USD în 1 zi
5,0 (2 recenzii)
2,0
2,0
Avatarul utilizatorului
Hi I'm a senior software engineer with 3 years experience. I think I can help you with debugging your code. Please share the test case that is failing Regards
$20 USD în 1 zi
0,0 (0 recenzii)
0,0
0,0

Despre client

Steagul UNITED STATES
Los Angeles, United States
5,0
1
Metoda de plată a fost confirmată
Membru din mar. 3, 2021

Verificarea clientului

Mulțumim! Ți-am trimis prin e-mail linkul pe care trebuie să-l accesezi pentru a revendica creditul gratuit.
A apărut o eroare la trimiterea e-mailului. Încearcă din nou.
Utilizatori înregistrați Totalul proiectelor postate
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Se încarcă previzualizarea
S-a oferit permisiunea de depistare a locației.
Ți-a expirat sesiunea pentru conectare sau te-ai deconectat. Conectează-te din nou.