Title | TP8 - Nombres binaires relatifs |
---|---|
Course | Théorie et pratique de la gestion des ressources humaines ( |
Institution | Université Paris Dauphine |
Pages | 4 |
File Size | 43.9 KB |
File Type | |
Total Downloads | 76 |
Total Views | 122 |
Voici les corrigés du TP 8 d'informatique VBA (DEGEAD 2)....
EXERCICE 1 : Sub Q11(n As Integer, li As Integer) Dim i As Integer If n < 0 Then Cells(li, 1) = 1 n = -n Else Cells(li, 1) = 0 End If For i = 8 To 2 Step -1 Cells(li, i) = n Mod 2 n=n\2 Next i End Sub
Sub test() Call Q11(-19, 2) End Sub
Function Q12(li As Integer) As Integer Dim i As Integer, s As Integer For i = 2 To 8 s = s + Cells(li, i).Value * 2 ^ (8 - i) Next i If Cells(li, 1).Value = 1 Then s = -s End If
dtb = s End Function
Sub test1() a = Q12(1) MsgBox a End Sub
EXERCICE 2 : Sub Q21(n As Integer, li As Integer) For i = 8 To 1 Step -1 Cells(li, i) = n Mod 2 n=n\2 If Cells(li, i) = 1 Then Cells(li, i) = 0 Else Cells(li, i) = 1 End If Next i i=8 Do If Cells(li, i) = 0 Then Cells(li, i) = 1 Else Cells(li, i) = 0 End If i=i-1
Loop Until Cells(li, i + 1) = 1 End Sub
Sub test2() Call Q21(2, 1) End Sub
Function Q22(li As Integer) As Integer Dim i As Integer, s As Integer For i = 1 To 8 s = s + Cells(li, i).Value * 2 ^ (8 - i) Next i If s > 127 Then s = s - 256 End If Q22 = s End Function
Sub test3() MsgBox Q22(1) End Sub
Exercice 3 : Function PlusGrand(li1, li2) As Integer Dim i As Integer For i = 1 To 8 If Cells (li1, i).Value > Cells (li2, i).Value Then
PlusGrand = l1 Exit Function Else If Cells (li1, i).Value < Cells (li2, i).Value Then PlusGrand = l2 Exit Function End If Next i End Function
Function PlusGrandR (li1, li2) As Integer Dim i As Integer If Cells(li1, i).Value > Cells(li2, i).Value Then PlusGrandR = li2 Exit Function ElseIf Cells(li1, i).Value < Cells(li2, i).Value Then PlusGrandR = li1 End If For i = 2 To 8 If Cells(li1, i).Value > Cells(li2, i).Value Then PlusGrandR = li1 Exit Function ElseIf Cells(li1, i).Value < Cells(li2, i).Value Then PlusGrandR = li2 Exit Function End If Next i End Function...