Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

How to convert decimal to any base

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-04-2009, 03:10 PM
Junior Member
 
Join Date: Nov 2008
Posts: 16
Question How to convert decimal to any base

How can a decimal input be converted to Hex, Octal,Binary or any Base.
I can do this in VB6 but can't seen to in BASIC4PPC. Problem lies in
trying to use the String Mid Function as given below.

Sub btnCalc_Click
Dim HexString
Dim DecValue

HexString = ""
DecValue = txtInput.Text

Do While DecValue > 0
'Get least significant character
HexString = mid("0123456789ABCDEF",Mod(DecValue,16 )+ 1,1) + HexString
'Remove least significant character

DecValue = Int(DecValue/16)
Loop

If len(HexString) < 2 Then
Decimal2Hex = "&H" + Right("00" + HexString,2)
Else
Decimal2Hex = "&H" + HexString
End If

txtOutput.Text = Decimal2Hex

End Sub
Any Help will be appreciated
Reply With Quote
  #2 (permalink)  
Old 06-04-2009, 03:30 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 1,057
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Hello johnpc,

a conversion between decimal, hexadecimal and binary values can easily be done with the bitwise.dll.


specci48
Reply With Quote
  #3 (permalink)  
Old 06-04-2009, 09:37 PM
pdablue's Avatar
Senior Member
 
Join Date: Sep 2007
Posts: 114
Default Binary, Decimal, Hexadecimal Conversion.

Hi,

There is a Binary, Decimal, Hexadecimal conversion
program example listed in the "Share Your Creations"
section of the B4PPC Forums.

This program uses the Bitwise.dll.

Check out the postings by PDABLUE.
Reply With Quote
  #4 (permalink)  
Old 06-04-2009, 10:42 PM
Basic4ppc Veteran
 
Join Date: May 2008
Location: Newcastle Upon Tyne - England
Posts: 271
Awards Showcase
Beta Tester 
Total Awards: 1
Default

To answer questions about your code:

Code:
...
HexString = <font color=
"Red">mid</font>("0123456789ABCDEF",Mod(DecValue,16 )+ 1,1) + HexString
If <font color="Red">len</font>(HexString) < 2 Then
Decimal2Hex = 
"&H" + <font color="Red">Right</font>("00" + HexString,2)
mid, len and right are not functions of Basic4PPC. you should use StrAt or SubString and StrLength
Reply With Quote
  #5 (permalink)  
Old 06-05-2009, 09:29 AM
Junior Member
 
Join Date: Nov 2008
Posts: 16
Smile How to convert decimal to any base

Thank You all - Resolved:
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Conectando a una base de datos remota Fernando Spanish Forum 4 04-17-2009 03:02 PM
Agregar registros desde otra base sqlite Fernando Spanish Forum 2 04-10-2009 01:18 PM
Encore une question sur la Base de donnée philsand77 French Forum 4 12-24-2008 04:01 PM
Stripping decimal places Softselect Questions (Windows Mobile) 11 11-14-2007 12:17 PM
B4PPC and decimal comma Scubaticus Questions (Windows Mobile) 12 07-03-2007 03:21 PM


All times are GMT. The time now is 04:28 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0