c - Converting char integer representations to binary -
i have char array composed of elements 5 3. array used represent number 53. should approach convert number of 3 chars binary equivalent? implementing in c, later on need rewritten in assembly. solution seek should purely low stuff work without helper libraries.
i stuck idea convert separately 5 , 4 (via mapping 5 , 4 ascii equivalents). yet idea not work sure. have idea convert char '5' int 5 right shifting byte 4. same 4. multiply 5 10 , add 4, , use division 2 algorithm find remainder , compose binary number.
in c:
int ascitointeger(char *c) { int result = 0; while (*c) { result *= 10; result += (*c - '0'); c++; } return result; } assumes input valid.
you can head start on assembly language version compiling switches output ... assembly language! example in gnu c: gcc -s -c ascii2int.c.
Comments
Post a Comment