# Creating a look up table/dictionary code

Page 1 of 1

## 1 Replies - 765 Views - Last Post: 13 September 2011 - 07:27 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=246918&amp;s=f2f0fbf26c39ec903dd30ccf74e013fa&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 kkasp

Reputation: 0
• 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

• D.I.C Regular

Reputation: 61
• 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.