Умножение и деление целых неотрицательных чисел в двоичном коде

Министерство образования Республики Таджикистан

Таджикский Технический Университет им. ак. М. С. Осими

Кафедра АСОИиУ

Лабораторная работа №3

“Умножение и деление целых неотрицательных чисел в двоичном коде”

Выполнил:

Принял:

-Душанбе 2009-

Программа UmnDelDouble.

Option Explicit

Public sel As Integer

Publici, x, j, x0 AsDouble Блок инициализации программы

Public c As Integer

Private Sub Command1_Click()

Fir. Text = “”

Sec. Text = “”

Res. Text = “”

X = 0 Процедура очистки содержимого полей

J = 0

X0 = 0

I = 0

End Sub

Private Sub ext_Click()

End

End Sub

Private Sub fir_Change()

If val(fir. Text) = 0 Or val(fir. Text) = 1 Then

Lb1.Caption = fir. Text

Exit Sub

Else

I = (Len(fir. Text))

X = 0

J = 0

Do Блок кодировки в “реальном времени”

X = x + (val(Mid(fir. Text, i, 1)) * (2 ^ j))

I = i – 1

J = j + 1

Loop Until i = 0

Lb1.Caption = x

End If

End Sub

Исходный вид окна приложения.

Private Sub fir_GotFocus()

Sel = 1

End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

On Error GoTo err:

If (KeyCode = vbKeyBack) Then

Select Case sel

Case 1

Fir. Text = Left(fir. Text, Len(fir. Text) – 1)

Case 2

Sec. Text = Left(sec. Text, Len(sec. Text) – 1)

End Select

Else

End If

Exit Sub

Err:

Beep

End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)

Dim val As String

Val = Chr(KeyAscii)

If (val >= “0”) And (val <= “9”) Then

If sel = 1 Then

Select Case val

Case “0”

Fir. Text = fir. Text &; “0”

Case “1” Процедуры

Fir. Text = fir. Text &; “1” контроля

End Select за вводом

ElseIf sel = 2 Then

Select Case val

Case “0”

Sec. Text = sec. Text &; “0”

Case “1”

Sec. Text = sec. Text &; “1”

End Select

Else

End If

Else

End If

End Sub

Private Sub Form_Load()

Umn. Value = True

C = 1

End Sub

Вид окна приложения с введенными данными.

Private Sub res_Change()

If val(res. Text) = 0 Or val(res. Text) = 1 Then

Lb3.Caption = res. Text

Exit Sub

Else

I = (Len(res. Text))

X = 0

J = 0

Do Блок кодировки в “реальном времени”

X = x + (val(Mid(res. Text, i, 1)) * (2 ^ j))

I = i – 1

J = j + 1

Loop Until i = 0

Lb3.Caption = x

End If

End Sub

PrivateSubrun_Click() ‘Основная процедура обработки

Dim d(90) As Double

If fir. Text = “” Or sec. Text = “” Then

MsgBox “Incorrect input. Please input numbers again”, , “=VaMp1r3=™”

Exit Sub

ElseIf val(lb2.Caption) = 0 Or val(lb1.Caption) = 0 Then

MsgBox “Incorrect input. Please input numbers again”, , “=VaMp1r3=™”

Call Command1_Click

Exit Sub

ElseIf val(lb2.Caption) = 0 And val(lb1.Caption) = 0 Then

MsgBox “Incorrect input. Please input numbers again”, , “=VaMp1r3=™”

Call Command1_Click

Exit Sub

Else

Select Case umn. Value

Case True

X0 = ((CDbl(lb1.Caption)) * (CDbl(lb2.Caption)))

X = 0

C = 1

Do

D(c) = x0 Mod 2

X = Round((CDbl(x0) / 2) – 0.3, 0)

C = c + 1

X0 = x

Loop Until x = 1

D(c) = x

Res. Text = “”

Do

Res. Text = res. Text &; d(c)

C = c – 1

Loop Until c = 0

Case False

If val(lb2.Caption) > val(lb1.Caption) Then

MsgBox “Incorrect Input. Please input numbers again.”, , “=VaMP1r3=™”

Exit Sub

Else

X0 = val(((CDbl(lb1.Caption)) / (CDbl(lb2.Caption))))

X = 0

C = 1

Do

If x0 = 0 Then Exit Do

D(c) = x0 Mod 2

X = Round((CDbl(x0) / 2) – 0.3, 0)

C = c + 1

X0 = x

Loop Until x = 1

D(c) = x

Res. Text = “”

Do

Res. Text = res. Text &; d(c)

C = c – 1

Loop Until c = 0

End If

End Select

End If

EndSub

Вид окна приложения с вычисленными данными.

Private Sub sec_Change()

If val(sec. Text) = 0 Or val(sec. Text) = 1 Then

Lb2.Caption = sec. Text

Exit Sub

Else

I = (Len(sec. Text))

X = 0

J = 0

Do Блок кодировки в “реальном времени”

X = x + (val(Mid(sec. Text, i, 1)) * (2 ^ j))

I = i – 1

J = j + 1

Loop Until i = 0

Lb2.Caption = x

End If

End Sub

Private Sub sec_GotFocus()

Sel = 2

End Sub


Умножение и деление целых неотрицательных чисел в двоичном коде