Microsoft Small Basic

Program Listing:
Embed this in your website
' Dump v0.1
'
CR = 13
LF = 10
TextWindow.Write("File name? ")
sFile = TextWindow.Read()
' The following line could be harmful and has been automatically commented.
' sBuf = File.ReadContents(sFile)
iDec = Text.GetLength(sBuf)
TextWindow.Write("File length = " + iDec + " (")
InitDec2Hex()
Dec2Hex()
TextWindow.WriteLine(sHex + "h) [bytes]")
iPtr = 1
c = " "
While c <> ""
  If Math.Remainder(iPtr, 16 * 8) = 1 Then
    TextWindow.WriteLine("")
    TextWindow.WriteLine(" +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F 0123456789ABCDEF")
    TextWindow.WriteLine(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ----------------")
  EndIf
  iDec = Math.Floor((iPtr - 1) / 16)
  Dec2Hex()
  If Text.GetLength(sHex) = 1 Then
    TextWindow.Write("00")
  ElseIf Text.GetLength(sHex) = 2 Then
    TextWindow.Write("0")
  EndIf
  TextWindow.Write(sHex)
  TextWindow.Write("0 ")
  iSave = iPtr
  For i = 1 To 16
    c = Text.GetSubText(sBuf, iPtr, 1)
    If c = "" Then
      sHex = " "
    Else
      iDec = Text.GetCharacterCode(c)
      Dec2Hex()
      If Text.GetLength(sHex) = 1 Then
        sHex = "0" + sHex
      EndIf
    EndIf
    TextWindow.Write(sHex + " ")
    iPtr = iPtr + 1
  EndFor
  TextWindow.Write(" ")
  iPtr = iSave
  For i = 1 To 16
    c = Text.GetSubText(sBuf, iPtr, 1)
    iDec = Text.GetCharacterCode(c)
    If iDec = CR Or iDec = LF Then
      TextWindow.Write(".")
    Else
      TextWindow.Write(c)
    EndIf
    iPtr = iPtr + 1
  EndFor
  TextWindow.WriteLine("")
EndWhile
'
' Initialize for subroutine Dec2Hex
' out: iBase
' out: sDigits
Sub InitDec2Hex
  iBase = 16
  sDigits="0123456789ABCDEF"
EndSub
'
' Decimal to Hexadecimal conversion
' in: iBase
' in: sDigits
' in: integer iDec
' work: integer n, d
' out: string sHex
Sub Dec2Hex
  sHex = ""
  n = iDec
loop:
    d = n - Math.Floor(n / iBase) * iBase
    sHex = Text.Append(Text.GetSubText(sDigits, d + 1, 1), sHex)
    n = Math.Floor(n / iBase)
  If n > 0 Then
    Goto loop
  EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.