Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Number Base Converter
Message
De
24/06/2004 20:27:14
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
24/06/2004 17:56:29
Fabian Belo
Independent Developer
Argentine
Information générale
Forum:
Java
Catégorie:
Autre
Divers
Thread ID:
00917041
Message ID:
00917073
Vues:
10
This message has been marked as a message which has helped to the initial question of the thread.
>Dear all;
>
>Does anyone has an algorithm to convert from base 8/16/2 to base 10?
>Thanks.

Let's see an example in octal:

234 (octal)

2 should be multiplied by 8^2 (8 square; right now, I don't remember the syntax in Java). 2 should be multiplied by 8, and 4, simply by 1.

A shortcut, which sort of bypasses the use of powers, is:

(2 * 8 + 3) * 8 + 4

IOW: repeatedly multiply by 8, and add the next digit.

For hexadecimal, you would have to convert "A" to 10... "F" to 15, first, and then apply the same algorithm (multiplying by 16, of course).

HTH,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform