Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
48
Task/Binary-digits/QB64/binary-digits.qb64
Normal file
48
Task/Binary-digits/QB64/binary-digits.qb64
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
Print DecToBin$(5)
|
||||
Print DecToBin$(50)
|
||||
Print DecToBin$(9000)
|
||||
|
||||
Print BinToDec$(DecToBin$(5)) ' 101
|
||||
Print BinToDec$(DecToBin$(50)) '110010
|
||||
Print BinToDec$(DecToBin$(9000)) ' 10001100101000
|
||||
|
||||
End
|
||||
|
||||
Function DecToBin$ (digit As Integer)
|
||||
DecToBin$ = "Error"
|
||||
If digit < 1 Then
|
||||
Print " Error number invalid for conversion to binary"
|
||||
DecToBin$ = "error of input"
|
||||
Exit Function
|
||||
Else
|
||||
|
||||
Dim As Integer TempD
|
||||
Dim binaryD As String
|
||||
binaryD = ""
|
||||
TempD = digit
|
||||
Do
|
||||
binaryD = Right$(Str$(TempD Mod 2), 1) + binaryD
|
||||
TempD = TempD \ 2
|
||||
Loop Until TempD = 0
|
||||
DecToBin$ = binaryD
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function BinToDec$ (digitB As String)
|
||||
BinToDec$ = "Error"
|
||||
If Len(digitB) < 1 Then
|
||||
Print " Error number invalid for conversion to decimal"
|
||||
BinToDec$ = "error of input"
|
||||
Exit Function
|
||||
Else
|
||||
Dim As Integer TempD
|
||||
Dim binaryD As String
|
||||
binaryD = digitB
|
||||
TempD = 0
|
||||
Do
|
||||
TempD = TempD + ((2 ^ (Len(binaryD) - 1)) * Val(Left$(binaryD, 1)))
|
||||
binaryD = Right$(binaryD, Len(binaryD) - 1)
|
||||
Loop Until Len(binaryD) = 0
|
||||
BinToDec$ = LTrim$(Str$(TempD))
|
||||
End If
|
||||
End Function
|
||||
Loading…
Add table
Add a link
Reference in a new issue