-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2873 from arielposada/main
Reto #14 - VBScript
- Loading branch information
Showing
2 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
Retos/Reto #14 - OCTAL Y HEXADECIMAL [Fácil]/vbscript/arielposada.vbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
' Ejemplo de uso: | ||
' cscript arielposada.vbs 128 | ||
' | ||
' Crea una función que reciba un número decimal y lo trasforme a Octal | ||
' y Hexadecimal. | ||
' - No está permitido usar funciones propias del lenguaje de programación que | ||
' realicen esas operaciones directamente. | ||
Option Explicit | ||
|
||
Function DecimalToOctal(decimalParam) | ||
Dim octal, i, decimal | ||
decimal = decimalParam | ||
octal = "" | ||
Do While decimal <> 0 | ||
i = decimal Mod 8 | ||
octal = i & octal | ||
decimal = Int(decimal / 8) | ||
Loop | ||
DecimalToOctal = octal | ||
End Function | ||
|
||
Function DecimalToHexadecimal(decimalParam) | ||
Dim hexadecimal, i, decimal | ||
hexadecimal = "" | ||
decimal = decimalParam | ||
Do While decimal <> 0 | ||
i = decimal Mod 16 | ||
Select Case i | ||
Case 10 | ||
hexadecimal = "A" & hexadecimal | ||
Case 11 | ||
hexadecimal = "B" & hexadecimal | ||
Case 12 | ||
hexadecimal = "C" & hexadecimal | ||
Case 13 | ||
hexadecimal = "D" & hexadecimal | ||
Case 14 | ||
hexadecimal = "E" & hexadecimal | ||
Case 15 | ||
hexadecimal = "F" & hexadecimal | ||
Case Else | ||
hexadecimal = i & hexadecimal | ||
End Select | ||
decimal = Int(decimal / 16) | ||
Loop | ||
DecimalToHexadecimal = hexadecimal | ||
End Function | ||
|
||
Dim number | ||
If WScript.Arguments.Count = 1 Then | ||
number = CInt(WScript.Arguments.Item(0)) | ||
Else | ||
WScript.Echo "Debe especificar el número como parámetro de entrada, ejemplo:" | ||
WScript.Echo "cscript arielposada.vbs 128" | ||
WScript.Quit | ||
End If | ||
|
||
WScript.Echo "Decimal: " & number | ||
WScript.Echo "Octal: " & DecimalToOctal(number) | ||
WScript.Echo "Hexadecimal: " & DecimalToHexadecimal(number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
print ("hello world"); |