18 views

Uploaded by Erik Peter Oosterwal

C:\Documents and Settings\oosteep\My Documents\data\basic\Convert Base2Base\module1.bas
Tuesday, March 01, 2011 2:26 PM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
Attribute VB_Name = "Module1" Function Base2Base(InputNumber As String, InputBase As Integer, OutputBase As Integer) As String Dim J, K, DecimalValue, X, MaxBase, InputNumberLength As Long Dim NumericBaseData, OutputValue As String ' ' ' ' ' ' ' Declare all variable

- SA Implementations
- UNIX commands
- Write a Program to Print- IMPROV
- 65 Tips for Migrating to Visual Studio Dot Net
- Summary of Chapter 1
- Assignment 2
- plc_cl150
- solT3
- String
- Import Processing
- An R Function for the Blau Index of Diversity
- f.txt
- Palindrome
- edma 360 unit planner decimals for standard 2
- c6713with Matlab User Manual1
- apiDoc
- avro-spec
- Numerical Foundations
- Saving and Reloading ListView using Shared Preferences [Saving onDestroy()] - Stack Overflow.pdf
- QBASIC Techniques

You are on page 1of 2

2 Function Base2Base(InputNumber As String, InputBase As Integer, OutputBase As Integer) As String

3

4 Dim J, K, DecimalValue, X, MaxBase, InputNumberLength As Long ' Declare all variables

5 Dim NumericBaseData, OutputValue As String '

6

7 '

8 ' Initialize the symbols used for converting from one base to another. 0-F are standard for

9 ' bases between 2-16. G-z (lower case) just seemed like a logical sequence of characters

10 ' to use. The others are more or less random characters used as typical text. The double

11 ' quote (") has to be placed twice for Visual Basic to understand it asa single character

12 ' and not the end of the string.

13 NumericBaseData = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ,.;:'""!?()$%#/\@+-={}[]<>"

14

15 MaxBase = Len(NumericBaseData) ' Generically set the maximum base to the

16 ' length of NumericBaseData. If another

17 ' programmer changes the number of

18 ' characters in that variable, this line

19 ' will self adjust.

20

21 If (InputBase > MaxBase) Or (OutputBase > MaxBase) Then ' Check to make sure the user isn't trying

22 Base2Base = "N/A" ' to use a base that's larger than

23 Exit Function ' the set of characters.

24 End If

25

26 '*/ Convert InputNumber to Base 10 /*

27

28 InputNumberLength = Len(InputNumber) ' We need to know how long the input number is.

29 DecimalValue = 0 ' Set the initial decimal value of the number to 0.

30

31 For J = 1 To InputNumberLength ' Check each digit in the input number

32 For K = 1 To InputBase ' compare it to the symbol set.

33 If Mid(InputNumber, J, 1) = Mid(NumericBaseData, K, 1) Then

34 DecimalValue = DecimalValue + Int((K - 1) * (InputBase ^ (InputNumberLength - J)) + 0.5)

35 End If

36 Next K ' Using the formula (above) convert the input value to its decimal representation.

37 Next J

38

39 '*/ Convert the Base 10 value (DecimalValue) to the desired output base /*

40

-1-

C:\Documents and Settings\oosteep\My Documents\data\basic\Convert Base2Base\module1.bas Tuesday, March 01, 2011 2:26 PM

42

43 ' As long as the decimal value is larger than 0 , then we've still got stuff to convert.

44 ' Find out which symbol needs to be tacked on to the output,

45 ' tack that symbol to the front of the output (we're converting from least significant

46 ' to most significant digit.)

47 ' Reduce the size of the decimal value by dividing by the output base value

48 While DecimalValue > 0

49 X = Int(((DecimalValue / OutputBase) - Int(DecimalValue / OutputBase)) * OutputBase + 1.5)

50 OutputValue = Mid(NumericBaseData, X, 1) + OutputValue

51 DecimalValue = Int(DecimalValue / OutputBase)

52 Wend

53

54 Base2Base = OutputValue ' Return the value

55

56 End Function

57

-2-

- SA ImplementationsUploaded byAbhishek Mallick
- UNIX commandsUploaded bymaheswaran90
- Write a Program to Print- IMPROVUploaded byAngel Ayushi
- 65 Tips for Migrating to Visual Studio Dot NetUploaded byObama Oliech Odinga
- Summary of Chapter 1Uploaded byjsandersjr
- Assignment 2Uploaded bySai Charan
- plc_cl150Uploaded byleandrolms
- solT3Uploaded byjza_es
- StringUploaded byshanysunny
- Import ProcessingUploaded byWan Aminudin
- An R Function for the Blau Index of DiversityUploaded byTsige Bayrau
- f.txtUploaded bySrinivasavaradan Es
- PalindromeUploaded byNikhil Sabu
- edma 360 unit planner decimals for standard 2Uploaded byapi-285732759
- c6713with Matlab User Manual1Uploaded bySugumar Sar Durai
- apiDocUploaded byHồ Vũ Hoàng
- avro-specUploaded bycalumm
- Numerical FoundationsUploaded by3CSN
- Saving and Reloading ListView using Shared Preferences [Saving onDestroy()] - Stack Overflow.pdfUploaded byShoaib Quraishi
- QBASIC TechniquesUploaded byElreder
- food block remoteUploaded byapi-360229604
- Difference between CLDC 1.0 & CLDC 1.1Uploaded byvrunda2906
- 4625-Intro-4Uploaded byBen Denny
- Elementary Linear Algebra Applications VUploaded byAhad Rasheed
- PharmaSUG-2012-TA08Uploaded byJas Rosy
- 9800_9500protocoldocUploaded byAntonio
- 5 Minute Math DailyUploaded byChibuzo Ajibola
- Managing Sequence of Operations in WCF Service for BeginnerUploaded bySugeng Fajarianto
- Image to Byte ArrayUploaded bySubin Ks
- Writr a c Program to Find the Length of the String Using StrlenUploaded byattaullahjohar040

- 6th International Conference on Learning, Education and Pedagogy (LEAP)Uploaded byGlobal Research and Development Services
- Impact Assessment of LV Networks Into MV NetworksUploaded byLimuel Estorque
- Mech. Systems-1.pptxUploaded bysatyanarayana_boddul
- 2 3 - city-states of ancient sumerUploaded byapi-236666161
- Labs and DiagnosticsUploaded byJae Kim
- Guruji s LecturesUploaded byNandan Kulkarni
- An Enzymatic Method to Process Decomposed Nonhuman Bone for Forensic Dna Analysis 2157 7145.1000220Uploaded byAhmad Shukri
- PT SMI Renewable Energy Event SeoulUploaded byR. Mega Mahmudia
- Performance of Radial Piston Type Reciprocating Expander for CO2 Refrigeration CycleUploaded byAnuar Mohamad
- copy of science fair project experiment self-assessmentUploaded byapi-397961863
- ATPGUploaded bybsnspkumar
- Add Adhd SmallUploaded byNikiEnDanieTolken
- GSI Forklift[1]Uploaded bym_arnone6017
- Assignment 1 (2)Uploaded bysameerverma_78
- CV BrazilUploaded byDavid Sosa
- Is Life Worth Living Without Immortality? - M. M. MANGASARIANUploaded byJack Maurice
- Application Security Guide SRM4.0Uploaded byoshkosh2553
- Cell Mol Life Sci 2004 FisoneUploaded byRia Devi
- 02-2010 Towhee Newsletter Tahoma Audubon SocietyUploaded byTahoma Audubon Society
- testUploaded bydovesnest_in
- How to Deal With Cockroach InvasionUploaded bypest control
- Manual Crt Ss9900 EngUploaded byAnonymous 2GVabYh40W
- ModulsUploaded byAgus Wawan Setiawan
- Project Duration Forecasting - Walt LipkeUploaded byJose Andrew Garcia Ibarra
- Journal.pone.0123230Uploaded bymilky1792
- 11-18-13 HIST133 LECTUREUploaded byHarjay Lazo Tamayo
- Step by Step Watercolor of WaterfallUploaded byTaza Motata
- Biochemistry IUploaded bySanthosh Kalash
- Structural Analysis of Fuselage With Lattice StructureUploaded bycena3135
- Basic Principles of Health EconomicsUploaded byMuna Hassan Mustafa