Pages: 1

How to convert infix to postfix (Python)

I wrote this originally some time ago. Mostly for my own amusement. It converts from infix to postfix notation.

I expect most of our readers know what these are but for the benefits of completeness infix is a functional notation we humans use for instance in mathematics where the operator sits in between the operands. Example:

(8 * 5) / 4

...

Read more

There are no comments on this post.

How to build a string representation of an integer in any base without bitwise operators

Last week I gave the geeks at #neverfear IRC a coding task, something I've been trying lately to both challenge them and myself. The challenge I gave them was actually a real-life problem I'd faced in industry as a developer. The challenge was as follows.

Produce an algorithm in the language of your choice that recursively converts a numerical value to a hexidecimal string without bitwise operators. Bonus points awarded for generalising your algorithm to the nth base.

We had a few good solutions mostly following a similiar approach in various languages that I'd like to share.

...

Read more

There are no comments on this post.

How many characters should you allocate for a string representation of any given integer in any given base

Once every while somebody asks how to calculate how many characters to allocate when building a string representation of an integer. This is actually a very easy problem.. when you know your maths.

The answer is simply to use logarithms!

floor(log10(number) + 1)

...

Read more

There are no comments on this post.

Pages: 1

Powered by Debian, Guinness, and excessive quantities of caffeine and sugar.