Home > Software engineering >  Consult everybody, ask how to complement the sign bit invert into a frameshift?
Consult everybody, ask how to complement the sign bit invert into a frameshift?

Time:11-19

A complement code is as follows:
Dim a (16) As an Integer, As Integer x
X=CInt (Text1. Text)
If x & gt;=0, Then a (16)=0 Else a (16)=1
X=Abs (x)
For I=1 To 15
A (I)=x Mod 2
X=x \ 2
Text2. Text=""
Next I
For I=16 To 1 Step - 1
Next I
For I=1 To 15
A (I)=1 - a (I)
Next I
Text2. Text=a (16)
For I=15 To Step 1-1
Next I
Text2. Text=a (16)
A (1)=a (1) + 1
I=1
While a (I)=2 And I & lt; 15
A (I)=0
A (I + 1)=a (I + 1) + 1
I=I + 1
Wend
For I=15 To Step 1-1
Text2. Text=Text2. Text & amp; A (I)
Next I

But there is no sign bit take VB as an operator, would like to ask bosses how to solve

CodePudding user response:

 
Option Explicit

Private Sub Command1_Click ()
Dim x As an Integer, y As Integer
X=CInt (Text1. Text)
Debug. Print the original code: "", x, Right (" 0000" & amp; Hex (x), 4), DEC2Bin (x)

'radix-minus-one complement: besides the sign bit, everyone take the
Y=(x And & amp; H8000) Or (Not) x
The Debug. Print "radix-minus-one complement:", y, Right (" 0000 "& amp; Hex (y), 4), DEC2Bin (y)

'complement: besides the sign bit, everyone invert, end with a
Y=(x And & amp; H8000) Or ((Not) x + 1)
The Debug. Print "complement:", y, Right (" 0000 "& amp; Hex (y), 4), DEC2Bin (y)

'move code to complement the sign bit invert
Y=(Not (x And & amp; H8000)) And ((Not) x + 1)
The Debug. Print "frameshift:", y, Right (" 0000 "& amp; Hex (y), 4), DEC2Bin (y)
The Debug. Print
End Sub

Private Function DEC2Bin (intX As Integer) As String
Dim strHex As String
Dim As Integer I
StrHex=Right (" 0000 "& amp; Hex (intX), 4)
For I=1 To 4
Select Case mids (strHex, I, 1)
Case "0"
DEC2Bin=DEC2Bin & amp; "0000"
Case "1"
DEC2Bin=DEC2Bin & amp; "0001"
Case "2", "
DEC2Bin=DEC2Bin & amp; "0010"
Case ", "3"
DEC2Bin=DEC2Bin & amp; "0011"
Case "4"
DEC2Bin=DEC2Bin & amp; "0100"
Case "5"
DEC2Bin=DEC2Bin & amp; "0101"
Case "6"
DEC2Bin=DEC2Bin & amp; "0110"
Case "7"
DEC2Bin=DEC2Bin & amp; "0111"
Case "8"
DEC2Bin=DEC2Bin & amp; "1000"
Case "9"
DEC2Bin=DEC2Bin & amp; "1001"
Case "A"
DEC2Bin=DEC2Bin & amp; "1010"
Case "B"
DEC2Bin=DEC2Bin & amp; "1011"
Case "C"
DEC2Bin=DEC2Bin & amp; "1100"
Case "D"
DEC2Bin=DEC2Bin & amp; "1101"
Case "E"
DEC2Bin=DEC2Bin & amp; "1110"
Case "F"
DEC2Bin=DEC2Bin & amp; "1111"

End the Select
Next

End the Function



Two case output:

The original code: 123, 007 b, 0000000001111011
Radix-minus-one complement: 1111111110000100-124 FF84
Complement: 1111111110000101-123 FF85
Move the code: 1111111110000101-123 FF85

The original code: 1111111110000101-123 FF85
Radix-minus-one complement: 1000000001111010-32646, 807 a
Complement: 1000000001111011-32645, 807 b
Move the code: 123, 007 b, 0000000001111011

CodePudding user response:

First of all, VB is the NOT operator, NOT is the NOT operator, and you are want the following the operation effect
 
Dim int_temp As Integer
Dim int_temp2 As Integer
Int_temp=int (Text1. Text)
Int_temp2=int_temp And & amp; H8000
Int_temp=Not int_temp
Int_temp=int_temp And & amp; H7FFF
Int_temp=int_temp + 1
If int_temp2 & lt;> 0 Then
Int_temp=int_temp Xor & amp; H8000
End the If
Text2. Text=int_temp
  • Related