tags:

views:

81

answers:

2

how to write a lisp program to convert given hexadecimal number into decimal. can somebody give me a clue. thank you

A: 

I'm assuming its a homework problem so i'll give you a hint in the right direction.

Here is how to convert decimal to binary ->

Lets say you start with the number 9 in binary its 1001. Start of by dividing 9 by 2. You get 4 with remainder 1. Save the remainder. Now divide that 4 by 2 again, you get 2 with remainder 0. Save the remainder. Divide that 2 again by 2, you get 1 with remainder 0. Save the remainder. Divide that 1 by 2 and finally you get 0 with reaminder 1. Save the remainder.

If you read the saved remainders backwards you get 1001! The binary number you've been looking for. Best to push the remainders on the stack and pop them back out, that way they'll come out backwards.

Nooby Programmer
A: 

It's already provided by Common Lisp.

  • The input is the string for the hex integer.

  • Then you parse the integer with radix 16

  • the result is the number

  • if you write the number with base 10 to an output stream, then you can get the number as a string in base 10

Rainer Joswig