Results 1 to 4 of 4

Thread: Example for Binary to decimal and decimal to binary conversions

  1. #1
    Senior Member
    Join Date
    Oct 2012
    Posts
    297
    Blog Entries
    5

    Example for Binary to decimal and decimal to binary conversions

    Code:
    Public Function Bin2Dec(Binary As String) As Long
    Dim NumLong As Long
    Dim MyInt As Integer 
    For MyInt = 1 To Len(Binary)
    NumLong = NumLong + (Mid(Binary, Len(Binary) - MyInt + 1, 1) * (2 ^ (MyInt - 1)))
    Next MyInt
    Bin2Dec = NumLong
    End Function
    Public Function Dec2Bin(MyNum As Long) As String
    Dim MyTemp As String
    Dim NumLong As Long
    NumLong = MyNum
    MyTemp = Trim(Str(NumLong Mod 2))
    NumLong = NumLong \ 2
    Do While NumLong <> 0
    MyTemp = Trim(Str(NumLong Mod 2)) & MyTemp
    NumLong = NumLong \ 2
    Loop
    Dec2Bin = MyTemp
    End Function

  2. #2
    Senior Member
    Join Date
    Oct 2012
    Posts
    297
    Blog Entries
    5
    This program will help you to convert binary value to decimal value and vise versa

  3. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    1
    yes !!!! It's useful for me !!!! TK a lot !!!


    ------------------------------------------
    coque lg g3 housse lg g3
    Last edited by romandeqaz123; 07-07-2014 at 04:02 AM.

  4. #4
    Senior Member suve's Avatar
    Join Date
    Jun 2012
    Posts
    444
    Very usefull post maha. It is very useful to me.
    Thanks

Similar Threads

  1. Replies: 0
    Last Post: 03-05-2013, 06:46 AM
  2. How to convert a decimal number to a binary one in C++
    By vishnu in forum Programming languages
    Replies: 2
    Last Post: 02-26-2013, 09:46 AM
  3. Replies: 0
    Last Post: 10-19-2012, 12:53 PM
  4. Replies: 1
    Last Post: 06-21-2012, 03:39 PM
  5. Binary Trees in c/C++, Maximum depth solution of the binary tree?
    By Santhi Katuri in forum Programming languages
    Replies: 1
    Last Post: 05-27-2012, 12:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •