|
-
Oct 10th, 2000, 12:09 PM
#1
Thread Starter
Hyperactive Member
I know how to do this math problem by hand, but i wouldnt know how to get a program to do it..... This is the problem
INPUT is 11:
_____
2| 11 = 5 Remainder 1
Take the answer 5
(Divide it by 2)
_____
2| 5 = 2 Remainder 1
Take the answer 2
(Divide it by 2)
______
2 | 2 = 1 Remainder 0
Take the answer 1
(Divide it by 2)
______
2 | 1 = 0
Now you take the remainders backwards...the answer is
1011
How the hell can i do that?
-RaY
VB .Net 2010 (Ultimate)
-
Oct 10th, 2000, 12:14 PM
#2
-
Oct 10th, 2000, 12:19 PM
#3
Thread Starter
Hyperactive Member
Thats my problem
If i try to divide using code i will get a decimal for example 2/11 is 5.5... how can i get .5 to remainder 1
-RaY
VB .Net 2010 (Ultimate)
-
Oct 10th, 2000, 12:36 PM
#4
New Member
i think this is it
Code:
Number = Text1.Text
Do
Remain = Number Mod 2
inText = Remain & inText
Text2.Text = Text2.Text & Number & " | " & 2 & "_ Remain " & Remain & vbNewLine
Number = Int(Number / 2)
Loop Until Remain = 0
Text2.Text = Text2.Text & inText
This should work... I've tested it, and it does with me 
LiNX
[Edited by LiNX on 10-11-2000 at 08:45 AM]
-
Oct 10th, 2000, 12:37 PM
#5
New Member
I'm not sure exactly how to write code for this problem, but I do know that Mod will give you the remainder of a division
example:
Dim math As Integer
math = 5 Mod 3
MsgBox math
you get the remainder 2
Hope this helps!
E-mail: [email protected]
“If the Answer to the Ultimate Question of Life, the Universe, and Everything is 42, what’s the question?”
-
Oct 10th, 2000, 01:19 PM
#6
Fanatic Member
Disclaimer: I know this is not the best way to do this, but I was just throwing something together while working on another project. But it will return the answer you are looking for using the MOD operator.
Also, using \ for division returns just the integer portion.
Code:
Private Sub command1_click()
Dim remainder1 As Integer
Dim remainder2 As Integer
Dim remainder3 As Integer
Dim remainder4 As Integer
Dim startNumber As Integer
Dim divNumber1 As Integer
Dim divNumber2 As Integer
Dim divNumber3 As Integer
Dim divNumber4 As Integer
Dim result As String
startNumber = 11
divNumber1 = startNumber \ 2
remainder1 = startNumber Mod divNumber1
divNumber2 = divNumber1 \ 2
remainder2 = divNumber1 Mod divNumber2
divNumber3 = divNumber2 \ 2
remainder3 = divNumber2 Mod divNumber3
divNumber4 = divNumber3 \ 2
If divNumber4 > 0 Then
remainder4 = divNumber3 Mod divNumber4
Else
remainder4 = 1
End If
result = remainder4 & remainder3 & remainder2 & remainder1
MsgBox result
-
Oct 10th, 2000, 03:56 PM
#7
Okay try this.
Put a textbox and command button on a form. Make sure the textbox and command button are off to the right of the form because the results will be printed on the form. In the command1 click event place this code:
Code:
IntegerToBinary (CInt(Text1.Text))
Add a module and paste this code
Code:
Sub IntegerToBinary(intNumber As Integer)
Dim intResult As Integer
Dim intRemainder As Integer
intResult = Fix(intNumber / 2)
intRemainder = (intNumber Mod 2)
Form1.Print intResult & " " & intRemainder
If intResult = 0 Then
Exit Sub
Else
IntegerToBinary (intResult)
End If
End Sub
Then just read the right column from the bottom up. There is probably a better way to output the results but I'm too sick right now.
I'm fairly new still so I hope this helps.
-
Oct 10th, 2000, 07:07 PM
#8
Frenzied Member
This is the complete answer
Try this one on for size...guaranteed to work every time! (at least with the number 11) 
Paste the following into a forms code window (or change Form_Load to Main and put it in a basic module):
Code:
Option Explicit
Private Sub Form_Load()
Dim Number As Long
Dim Remainder As Long
Dim Result As Long
Dim Answer As String
Number = CLng(InputBox("Enter a number, please:", "FallnWrld"))
Do
Remainder = GetRemainder(Number, Result)
Number = Result
Answer = CStr(Remainder) & Answer
Loop While Result > 0
MsgBox "Answer = " & Answer
Unload Me
End Sub
Private Function GetRemainder(Number As Long, Result As Long) As Long
Result = CLng(Int(Number / 2))
GetRemainder = CLng(Int(Number Mod 2))
End Function
Who's the man???

Hope that helps!
-
Oct 10th, 2000, 08:46 PM
#9
Lively Member
THIS A DYNAMIC WAY. YOU CAN USE ANY TWO NUMBERS!!!
'Need:
'Text1 for numerator
'Text2 for denominator
'Command1 for code below
Dim strRemaindor As String
Dim conRemaindor As String
Dim intNumerator As Integer
Dim intDenominator As Integer
Dim intRemaindor As Integer
Dim intResult As Integer
strRemaindor = ""
intNumerator = Text1
intDenominator = Text2
10
intResult = intNumerator \ intDenominator
intRemaindor = intNumerator Mod intDenominator
intNumerator = intResult
Select Case intRemaindor
Case 0
conRemaindor = "0"
Case 1
conRemaindor = "1"
Case 2
conRemaindor = "2"
Case 3
conRemaindor = "3"
Case 4
conRemaindor = "4"
Case 5
conRemaindor = "5"
Case 6
conRemaindor = "6"
Case 7
conRemaindor = "7"
Case 8
conRemaindor = "8"
Case 9
conRemaindor = "9"
End Select
strRemaindor = strRemaindor & conRemaindor
If intResult <> "0" Then GoTo 10
response = MsgBox("Rev Rem is: " & strRemaindor, vbOkOnly)
0101011001000010
01101111011011100110110001101001011011100110010101110010
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
|