En cours

I need a Programmer

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




$ cat [login to view URL] | ./ascii2bin ; echo $?



$ cat [login to view URL] | ./ascii2bin ; echo $?



$ cat [login to view URL] | ./ascii2bin ; echo $?



$ cat [login to view URL] | ./ascii2bin ; echo $?



$ cat [login to view URL] | ./ascii2bin ; echo $?


Compétences : Programmation C

en voir plus : be real google i need an editor and you playing games, hello i need urgent typist you just have to write in notepad from image i, i need programmer for contact form, i need programmer write code, i need some one to rewrite some articles which are on ocr pdf so you need to to be good at ocr conversion as well, i need a sales personnel job at achimota, i need programmer, i need programmer a site in india, i need programmer for a project, i need programmer paraphrasing, i need programmer to debug my code, i need to write a welcome at church, what do i need to print t shirts at home, git need merge error you need to resolve your current index first, what do i need to file my taxes at h&r block, what do i need to make t shirts at home, i need more, can you help me feed my sin, i need more can you help me rock song, i need some help you can never ask me, i need to speak to someone at facebook

Concernant l'employeur :
( 0 commentaires ) Los Angeles, United States

Nº du projet : #29458100

Décerné à:


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() Plus

%selectedBids___i_sum_sub_4% %project_currencyDetails_sign_sub_5% USD en 1 jour
(0 Commentaires)

10 freelances font une offre moyenne de 23 $ pour ce travail


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.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(541 Commentaires)

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.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(159 Commentaires)

###### 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 Scien Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(26 Commentaires)

Hi, "I have gone through your description. "This is my area of specialization, i can get it done 100 % perfectly well. Please ping me in person. I can help you to complete all tasks. I have hands-on experience in Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(19 Commentaires)

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 desire Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(3 Commentaires)

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 experienc Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(7 Commentaires)

Dear Sir. As an experienced C/C++ programmer, it is interesting to me. I have been working on various C/C++ projects for 7+ years. I have read your project description carefully and I can surely do it in an hour, even Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 7 jours
(4 Commentaires)

Hi; i can help you Now (immediately) send me a message so that we can discuss more. Thanks and regards.

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(1 Évaluation)

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

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(0 Commentaires)