Results 1 to 3 of 3

Thread: Convert Integer to a String in Binary Notation

  1. #1
    Join Date
    Jan 2009
    Posts
    91

    Convert Integer to a String in Binary Notation

    Hello friends,

    I am facing an issue while coding.I want to convert integer into its binary equivalent using VBScript.

    Can any one Fix this issue for me.

    Thanks in Advance.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Convert Integer to a String in Binary Notation

    Try to use this code i hope it will work for you.

    HTML Code:
    Function IntToBin(ByVal IntegerNumber As Long)
          
              IntNum = IntegerNumber
              Do
                  
                  TempValue = IntNum Mod 2
                  BinValue = CStr(TempValue) + BinValue
                          
                 
                  IntNum = IntNum \ 2
              Loop Until IntNum = 0
              
              IntToBin = BinValue
              
          End Function
          
          Function BinToInt(ByVal BinaryNumber As String)
          
             
              Length = Len(BinaryNumber)
    
              
              For x = 1 To Length
                  TempValue = TempValue + Val(Mid(BinaryNumber, Length - x + 1, 1)) * 2 ^ (x - 1)
              Next
              
              BinToInt = TempValue
              
          End Function
          
          Private Sub Command1_Click()
             
              Text2.Text = IntToBin(Val(Text1.Text))
          End Sub
          Private Sub Command2_Click()
             
              Text4.Text = BinToInt(Text3.Text)
          End Sub

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Convert Integer to a String in Binary Notation

    Use this is code

    HTML Code:
    SUB IntToBin (byte%, bin$)         'Add STATIC here to get SUB to
    bin$ = ""                          'work in QuickBasic 3.00
    temp% = byte%
    
            FOR i = 0 TO 7
                    IF temp% AND 1 THEN
                            bin$ = "1" + bin$
                    ELSE
                            bin$ = "0" + bin$
                    END IF
                     temp% = temp% \ 2
            NEXT
    
    END SUB

Similar Threads

  1. Problem to convert binary to string
    By steg in forum Software Development
    Replies: 1
    Last Post: 08-04-2011, 01:21 AM
  2. integer to string conversion
    By cyber-noob in forum Software Development
    Replies: 4
    Last Post: 03-03-2010, 10:26 PM
  3. Extract the integer from a string
    By New ID in forum Software Development
    Replies: 5
    Last Post: 26-02-2010, 12:31 AM
  4. Regex replace an integer with string
    By New ID in forum Software Development
    Replies: 5
    Last Post: 05-02-2010, 01:35 AM
  5. Convert string to binary in java
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 28-01-2010, 01:36 PM

Tags for this Thread

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
  •  
Page generated in 1,714,264,089.21094 seconds with 17 queries