Pascal

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

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
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 > hexadecimal
decimal > binary
hexadecimal > binary
binary > hezadecimal
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


Report
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 > hexadecimal
: decimal > binary
: hexadecimal > binary
: binary > hezadecimal
: 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!

The way I did it in my program was this:

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 :)

Report
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 > hexadecimal
: : decimal > binary
: : hexadecimal > binary
: : binary > hezadecimal
[...]
: 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

Report
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.

Report
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!!!
Reading Your code I know how to do it in Pascal,
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?
Your help was helpfull

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
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.