|
-
Oct 5th, 2000, 08:00 AM
#1
Thread Starter
Hyperactive Member
A program will input any interger value between 0 and 15 then the algorithm is to convert that value to binary (base2). The number input and its equivalent binary value are to be printed out.
Can anyone show an algorithm representing that?
I know it is something like...lets say if they inputed 11 in the text field it has to be divded by 2, the answer will be 5.5.....then you have to put that 5 over 2 and get 2.2? and then bahhhhh im lost any help guys?
-RaY
VB .Net 2010 (Ultimate)
-
Oct 5th, 2000, 08:06 AM
#2
Fanatic Member
This function takes a byte and converts it to binary:
Code:
Function Getbits(Invoer As Byte) As String
Dim Uitvoer As String
If (Invoer And 128) = 128 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
If (Invoer And 64) = 64 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
If (Invoer And 32) = 32 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
If (Invoer And 16) = 16 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
If (Invoer And 8) = 8 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
If (Invoer And 4) = 4 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
If (Invoer And 2) = 2 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
If (Invoer And 1) = 1 Then
Uitvoer = Uitvoer & 1
Else
Uitvoer = Uitvoer & 0
End If
Getbits = Uitvoer
End Function
You can use it like this:
Code:
Msgbox Getbits(CByte(Cint(Text1.Text)))
-
Oct 5th, 2000, 08:10 AM
#3
Thread Starter
Hyperactive Member
Sad enough
He wants it to be the drawn out long way, anyone know how to do that?
-RaY
VB .Net 2010 (Ultimate)
-
Oct 5th, 2000, 08:17 AM
#4
Thread Starter
Hyperactive Member
and not # 0 - 15 not bytes
The problem is he was showing it in q basic...and told us we can use any language we want to do it but cant use no short cuts have to show it step by step....I chose vb but need help i dont understand........if you dont know how to make the algorithm do you at least know the steps to convert the number? My had writing was so sloppy im lost.
-RaY
VB .Net 2010 (Ultimate)
-
Oct 5th, 2000, 08:21 AM
#5
Thread Starter
Hyperactive Member
I got something like this in notes
More like psecode(SP)
Input 11
Divide 2
Answer 5.5
Int(5.5) = (cant read looks like Se maybe < 0)
if (5.5 = 5) >0 then
4th digit = 1
else 4th digit = 0
end if
5
- = 2.5 Int(2.5(Cant read looks like (2.5+2)
2
If 2.5 - 2 > other
3rd digit = 1
etc.
-RaY
VB .Net 2010 (Ultimate)
-
Oct 5th, 2000, 08:22 AM
#6
Frenzied Member
Its been a while since I've done this but try:
Code:
Public Function GetBits(ByVal Number As Integer) As String
Dim I As Integer
Dim Buffer As String
For I = 0 To 15
If (Number Mod (2 ^ I)) = 0 Then
Buffer = "0" & Buffer
Else
Buffer = "1" & Buffer
End If
Next I
GetBits = Buffer
End Function
I don't know if thats exactly right but that should give you a good start. (I hope)
-
Oct 5th, 2000, 08:51 AM
#7
Thread Starter
Hyperactive Member
Thanks
I'll see what i can get out of it....do you know the steps by hand to convert a number into binary? This would help as well..... By the way Lewis....that download the first level link on your site doesnt seem to work?.......Thanks!
-RaY
VB .Net 2010 (Ultimate)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|