converter - (Pascal) Read and use a variable one number/character at the time -


i'm working on project i've gotten stuck. need make pascal program capable of converting number of base (2-16) decimal (10). problem i can't use things array/string/readkey/type, etc. i'm stuck only basic functions repeat/while/for/if/case, etc. problem arises how need input variable. needs be:

-"base:number."

-"answer in base 10"

for example

-16:123.

-291

i can't separate base number using ":". i'm not sure of how separate numbers. thought using ord seems way have no idea put it, or how write it. ideas?

you don't need arrays or of stuff. exercise wants apply knowledge of 2 things: how process input 1 character @ time, recognizing semaphores (the colon ':'), , understanding of how digits of number related base.

the radix of number not intrinsic quality of number -- 7 7 7 no matter radix represent in. radix textual, human-readable characteristic of number. have learned how handle polynomials in school:

567 → 5×10² + 6×10¹ + 7×10⁰ 

that 10 in there radix → base 10. if use hexadecimal (base 16) radix 16:

567₁₆ → 5×16² + 6×16¹ + 7×16⁰ 

the final trick understand how compose , decompose numbers using radix via multiplication , remainder operations. let's rewrite polynomial make more obvious:

567₁₆ → 5×16×16 + 6×16 + 7×1 

that 5 there in third-from-the-right position because multiplied 16 two times. 6 in second-from-the-right position because multiplied 16 one time. , 7 in rightmost position because multiplied 16 zero times. in code, that's:

n := 0; n := n * 16 + 5; n := n * 16 + 6; n := n * 16 + 7; writeln( 'n = ', n ); 

for specific assignment, first number (before colon ':') in base 10. second number (after colon ':') uses radix given first number.

good luck!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -