Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 119,692 VB.NET Programmers for FREE! Ask your question and get quick answers from experts. There are 2,096 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!




Base to Any Base

Convert Between Binary, Octal, Decimal & Hexidecimal.

Submitted By: AdamSpeight2008
Actions:
Rating:
Views: 232

Language: VB.NET

Last Modified: July 2, 2008

Snippet


  1. Private Function FromBaseToBase(ByRef s As String, ByVal fromBase As Integer, ByVal ToBase As Integer) As String
  2.  If (fromBase <> 2) Or (fromBase <>8) or (fromBase<>10) or (fromBase<>16) Then Return ""
  3.  If (ToBase<> 2) Or (ToBase<>8) or (ToBase<>10) or (ToBase<>16) Then Return ""
  4.  If s.length=0 then return ""
  5.  ' Convert (Convert to from base) to ToBase
  6.  Return Convert.ToString(Convert.ToInt32(s, fromBase), ToBase)
  7. End Function

Copy & Paste


Comments


AdamSpeight2008 2008-07-02 10:12:26

Modified: Due to me not fully testing the original. (I didn't test with any other bases, doh!) By the the time I realised the snippet had be submitted.


Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month