1 Replies - 765 Views - Last Post: 13 September 2011 - 07:27 PM Rate Topic: -----

#1 kkasp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 12-September 11

Creating a look up table/dictionary code

Posted 12 September 2011 - 03:34 PM

Hello,
One more question to get some help as my professor is not responding to emails and this class is 100% online.

Here is the information and what I have created. Let me know!
GUIDELINES:
-Develop an algorithm to convert from binary to decimal using a power of base.
-Define a function named repToDecimal that expects two arguments (second should
be a base), a string, and an integer.
-Function should use a lookup table to find the value of any digit and is
initialized before the function is defined.
-Value stored with each key should be the integer that the digit represents.
-Main loops of the function should convert each digit to uppercase,
look up its value in the table, and use this value in the computation.
-MAIN function included to test the conversion function with numbers in several

binToDecimalTable= {'0':'0', '1':'1', '2':'2','3':'3', '4':'4',

                                '5':'5', '6':'6', '7':'7', '8':'8', '9':'9', '10':'A',

                                '11':'B', '12':'C', '13':'D', '14':'E', '15':'F'}

def repToDecimal(number, table):

   binary = ''

   for digit in number:

        binary = binary + table[digit]

        return binary

repToDecimal ("29D",binToDecimalTable)



Is This A Good Question/Topic? 0
  • +

Replies To: Creating a look up table/dictionary code

#2 scalt  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 342
  • Joined: 22-November 07

Re: Creating a look up table/dictionary code

Posted 13 September 2011 - 07:27 PM

Hi

Did you copy the guidelines exactly as they were given to you? They don't make a whole lot of sense to me, binary data is usually represented by 1s and 0s, so you input string would probably look like '10010101110100100'. You wouldn't usually use a lookup table for this and there would be no need for converting characters to upper case. The coverter you've written doesn't look too bad though, however strictly speaking it is a 'hexadecimal to decimal' converter.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1