d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > I Need Halp > With This Thing
Add Reply New Topic New Poll
Member
Posts: 25,563
Joined: Mar 10 2007
Gold: 0.71
Jun 4 2013 07:10am
Realized we aren't allowed to post links
Quote
Useful Binary Conversion. This program convert Binary to text and text to binary. This program has one Form1 (Main.frm), textbox (Text1.Text), two button, (cmdConvtoBin and cmdConvtoText) and a module1 (Binary.bas)



Private Sub cmdConvtoBin_Click()
MainText = Text1.Text
ConvertBin MainText
Text1.Text = MainText
End Sub
Private Sub cmdConvtoText_Click()
MainText = Text1.Text
ConvertToText MainText
Text1.Text = MainText
End Sub
Private Sub Form_Load()
Text1.Text = ""
End Sub


I was looking at this tutorial for a binary code convertor for visual basic 2006 for a school project. What does it mean by binary.bas? I know how to add module but how do i add that one?

thanks :3

This post was edited by Denzel on Jun 4 2013 07:11am
Member
Posts: 16,450
Joined: Mar 25 2012
Gold: 158.71
Jun 4 2013 11:43am
from duck with abs
Quote
i don't see why you need an outside module to do binary conversions.
they are one of the most simplest things to do really and take literally less than 10 lines for each conversion to create the function.

Code
output:

5
101
1100001 1100010 1100100 1110101 1100011 1110100
abduct



Code
def bin2dec( number )
  result = 0
  number.split(//).each do |digit|
     result = (digit.to_i + result) * 2
  end
  return result/2
end

def dec2bin( number )
  number = number.to_i;
  return 0 if( number == 0 )
  result = '';
 
  while( number != 0 )
     result = (number % 2).to_s + result;
     number = number / 2;
  end
  return result;
end

puts bin2dec '101'
puts dec2bin 5

mystring = "abduct"
binaryarray = []
chararray = []

mystring.each_char do |char|
 binaryarray.push dec2bin char.ord
end

puts binaryarray.join ' '

binaryarray.each do |binary|
 chararray.push (bin2dec binary.to_s).chr
end

puts chararray.join ''


This post was edited by dolarsignzeroxeighty on Jun 4 2013 11:45am
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll