Pascal

Moderators: None (Apply to moderate this forum)
Number of posts: 14004

This Forum Only

conversion Bin2Hex Hex2Bin Bin2Dec etc... Posted by dmicfg on 10 Nov 2001 at 5:16 PM
Hi, I am just new in Pascal and programming too.
Sorry for novice faux-pa's
I've just lookin for algotims for converting numbers
decimal > binary
I just want to convert digit by digit without using any
external units.
Any links? Perhaps explanation how can I do it in Pascal?
But please, no source code, I want to do it by myself.
I have to learn it- not only to do it!
Robert

Re: conversion Bin2Hex Hex2Bin Bin2Dec etc... Posted by Manning on 10 Nov 2001 at 6:19 PM
: Hi, I am just new in Pascal and programming too.
: Sorry for novice faux-pa's
: I've just lookin for algotims for converting numbers
: decimal > binary
: I just want to convert digit by digit without using any
: external units.
: Any links? Perhaps explanation how can I do it in Pascal?
: But please, no source code, I want to do it by myself.
: I have to learn it- not only to do it!

First, convert the number to base10 (if its not already). From there, convert it to the destination base format.

And here is an explanation of how to do that. It would be easier with source, but hopefully you will understand this.

To convert to decimal:

Start at the rightmost number. It's decimal value is Number * Base ^ 0. As you move to the left, increase the power by 1 (so the 2nd to rightmost number's value is Number * Base ^ 1)

To convert from decimal to any other base:

Divide the base 10 number by the target base. The first number for the target base will be the remainder. Truncate the new base 10 number (get rid of the remainder), and repeat the process until you get to 0. (Eventually you will because 1 divided by anything greater than 1 is 0 remainder 1)

Hope that helps. I know its probably more confusing than anything :)

Re: conversion Bin2Hex Hex2Bin Bin2Dec etc... Posted by dmicfg on 11 Nov 2001 at 1:03 PM
[...]
: : I've just lookin for algotims for converting numbers
: : decimal > binary
[...]
: First, convert the number to base10 (if its not already).
OK. It's clear. First: Any>Dec Then:Dec>Hex Or/And Dec>Bin

: easier with source, but hopefully you will understand this.
I'm breakin up.1) I understand mechanism of converting "on the paper" but I can't do that i pascal. Tables? Input to table (char) and ... Your Source will BE helpful.
Thanks for fast help!!!2)
Robert

1)As You notice English is not my origin language
2)Help at once-make it twice - poor translation of p.proverb

Re: conversion Bin2Hex Hex2Bin Bin2Dec etc... Posted by Manning on 11 Nov 2001 at 3:48 PM
: I'm breakin up.1) I understand mechanism of converting "on the paper" but I can't do that i pascal. Tables? Input to table (char) and ... Your Source will BE helpful.

If you go to http://www.mannsoft.ca, there is a link to a program called MannBaseConv (off to the left). It is the program I wrote. Inside the .DPR file is a function called BaseToBase. It wont directly compile using Borland Pascal or anything because I wrote it in Delphi, but it will show you the code I used at least. It shouldnt take too much work to make it compile.

Re: conversion Bin2Hex Hex2Bin Bin2Dec etc... Posted by dmicfg on 12 Nov 2001 at 11:05 AM
: : I'm breakin up.
: [...]it will show you the code I used at least. It shouldnt take too much work to make it compile.
Thanks!!!
I think now I can try it even in C++ :)
I'll try do post to You TP source, I will write -
to look at, can I?

pozdrowienia
Robert
the forester

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic