Results 1 to 5 of 5

Thread: ASCII Table

Threaded View

  1. #1

    Thread Starter
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    ASCII Table

    The following class can be used to create your own ASCII table. To see how this is used Format Byte Array

    Code:
    Class ASCIITable
        ' USAGE:
        'Dim myTab As New ASCIITable
        'RichTextBox1.Text = myTab.ShowTable
    
        'note: the font must be a fixed width font such as Courier
        'this is intended to be used with 7-8 bit character sets
    
        ''' <summary>
        ''' non-printable(not visible) characters
        ''' </summary>
        ''' <remarks></remarks>
        Enum nopr 'default encoding
            NUL ' Null character
            SOH ' Start of Header
            STX ' Start of Text
            ETX ' End of Text
            EOT ' End of Transmission
            ENQ ' Enquiry
            ACK ' Acknowledgment
            BEL ' Bell
            BS ' Backspace
            HT ' Horizontal Tab
            LF ' Line feed
            VT ' Vertical Tab
            FF ' Form feed
            CR ' Carriage return
            SO ' Shift Out
            SI ' Shift In
            DLE ' Data Link Escape
            DC1 ' Device Control 1 (oft. XON)
            DC2 ' Device Control 2
            DC3 ' Device Control 3 (oft. XOFF)
            DC4 ' Device Control 4
            NAK ' Negative Acknowledgement
            SYN ' Synchronous idle
            ETB ' End of Transmission Block
            CAN ' Cancel
            EM ' End of Medium
            S_B ' SUB Substitute _ replaced with U
            ESC ' Escape
            FS ' File Separator
            GS ' Group Separator
            RS ' Record Separator
            US ' Unit Separator
            SPC ' Space
            DEL = 127 ' Delete
            SHYP = 173 ' Soft Hypen - depends on encoding
            NBSP = 255 'NBSP
        End Enum
    
        Class aChar
            Property ch As String
            Property dec As String
            Property hex As String
            Property oct As String
            Property bin As String
            Property visibleprint As Boolean = True
            Property code As Integer
            Property ctrlseq As String = ""
    
            Public Sub New(code As Integer, s As String)
                Me.code = code
                Me.ch = s.PadRight(5, " "c).Replace(Chr(255), "*")
                Me.dec = code.ToString.PadLeft(3, " "c)
                Me.hex = Convert.ToString(code, 16).PadLeft(2, "0"c).ToUpper
                Me.oct = Convert.ToString(code, 8).PadLeft(3, "0"c)
                Me.bin = Convert.ToString(code, 2).PadLeft(8, "0"c)
                If s.StartsWith(Chr(255)) Then Me.visibleprint = False
                If code < 32 AndAlso Not Me.visibleprint Then
                    Me.ctrlseq = "CTRL " & Chr(code + 64)
                End If
            End Sub
        End Class
    
        Property theChars As New Dictionary(Of Integer, aChar)
        Private _sb As New System.Text.StringBuilder
    
        Private _encodingUsed As System.Text.Encoding
        Public Property encodingUsed() As System.Text.Encoding
            Get
                Return Me._encodingUsed
            End Get
            Set(ByVal value As System.Text.Encoding)
                Me._encodingUsed = value
                For x As Integer = 0 To 255
                    Dim c As New aChar(x, Me.showChar(x))
                    Me.theChars.Add(x, c)
                Next
            End Set
        End Property
    
        Private NoPrint() As nopr = CType([Enum].GetValues(GetType(nopr)), nopr())
    
        Public Sub New()
            'create a list of all chars
            Me.encodingUsed = System.Text.Encoding.Default
        End Sub
    
        Public Sub New(enc As System.Text.Encoding)
            Me.encodingUsed = enc
        End Sub
    
        Public Function ShowTable(Optional showExtended As Boolean = False) As String
            Me._sb.Clear()
            Me.MSBHdr(0)
            'the dased line
            Dim s As String = New String("-"c, Me._sb.Length - 2) & Environment.NewLine
            Me._sb.Append(s)
            'create header line
            Me._sb.Append("   lsb | ") 'least significant bits
            For x As Integer = 1 To 4
                Me._sb.Append(String.Format(" {0}  {1} {2}  {3} |", "Char", "Dec", "Hex", "Oct"))
            Next
            Me._sb.AppendLine()
            Me._sb.Append(s) 'another dashed line
    
            'create rows
            Me.doRows(0)
            If showExtended Then
                Me._sb.AppendLine()
                Me.MSBHdr(4)
                Me.doRows(128)
            End If
            Me._sb.AppendLine()
            Me._sb.AppendLine("Encoding: " & Me.encodingUsed.EncodingName & " " & Me.encodingUsed.HeaderName & " " & "")
            Me._sb.AppendLine("Note: * indicates characters that are non-printing (not visible).")
            Me._sb.AppendLine()
            Me._sb.AppendLine("Control Characters")
            Me._sb.AppendLine("  to send       press simultaneously")
            For Each c As aChar In Me.theChars.Values
                If Not c.visibleprint Then
                    If c.code = 32 Then Exit For
                    Me._sb.AppendLine(String.Format(" {0}  {1,2}      {2}", c.ch, c.code, c.ctrlseq))
                End If
            Next
            'Debug.WriteLine(Me.ToString)
            Return Me._sb.ToString
        End Function
    
        Private Sub MSBHdr(start As Integer)
            'create most significant bit header
            Me._sb.Append(" msb ->  ")
            For x As Integer = start To start + 3
                Me._sb.Append(String.Format(" {0}  {1} {2}  |", "      ", Convert.ToString(x, 2).PadLeft(3, "0"c), "     "))
            Next
            Me._sb.AppendLine()
        End Sub
    
        Private Sub doRows(start As Integer)
            'create rows
            For r As Integer = 0 To 31
                'create least significant bits
                Me._sb.Append(String.Format(" {0} | ", Convert.ToString(r, 2).PadLeft(5, "0"c)))
                For c As Integer = start To start + 96 Step 32
                    Dim ch As Integer = r + c 'calc char to show
                    Dim ac As aChar = Me.theChars(ch)
                    Me._sb.Append(String.Format(" {0} {1} x{2} o{3} |", ac.ch, ac.dec, ac.hex, ac.oct))
                Next
                Me._sb.AppendLine()
            Next
        End Sub
    
        Private Function showChar(code As Integer) As String
            If Me.NoPrint.Contains(DirectCast(code, nopr)) Then
                Return Chr(255) & DirectCast(code, nopr).ToString.Replace("_"c, "U"c)
            Else
                Dim b(0) As Byte
                b(0) = CByte(code)
                Return Me.encodingUsed.GetChars(b)
            End If
        End Function
    End Class

    What the table looks like:


    Code:
     msb ->           000        |         001        |         010        |         011        |
    ---------------------------------------------------------------------------------------------
       lsb |  Char  Dec Hex  Oct | Char  Dec Hex  Oct | Char  Dec Hex  Oct | Char  Dec Hex  Oct |
    ---------------------------------------------------------------------------------------------
     00000 |  *NUL    0 x00 o000 | *SPC   32 x20 o040 | @      64 x40 o100 | `      96 x60 o140 |
     00001 |  *SOH    1 x01 o001 | !      33 x21 o041 | A      65 x41 o101 | a      97 x61 o141 |
     00010 |  *STX    2 x02 o002 | "      34 x22 o042 | B      66 x42 o102 | b      98 x62 o142 |
     00011 |  *ETX    3 x03 o003 | #      35 x23 o043 | C      67 x43 o103 | c      99 x63 o143 |
     00100 |  *EOT    4 x04 o004 | $      36 x24 o044 | D      68 x44 o104 | d     100 x64 o144 |
     00101 |  *ENQ    5 x05 o005 | %      37 x25 o045 | E      69 x45 o105 | e     101 x65 o145 |
     00110 |  *ACK    6 x06 o006 | &      38 x26 o046 | F      70 x46 o106 | f     102 x66 o146 |
     00111 |  *BEL    7 x07 o007 | '      39 x27 o047 | G      71 x47 o107 | g     103 x67 o147 |
     01000 |  *BS     8 x08 o010 | (      40 x28 o050 | H      72 x48 o110 | h     104 x68 o150 |
     01001 |  *HT     9 x09 o011 | )      41 x29 o051 | I      73 x49 o111 | i     105 x69 o151 |
     01010 |  *LF    10 x0A o012 | *      42 x2A o052 | J      74 x4A o112 | j     106 x6A o152 |
     01011 |  *VT    11 x0B o013 | +      43 x2B o053 | K      75 x4B o113 | k     107 x6B o153 |
     01100 |  *FF    12 x0C o014 | ,      44 x2C o054 | L      76 x4C o114 | l     108 x6C o154 |
     01101 |  *CR    13 x0D o015 | -      45 x2D o055 | M      77 x4D o115 | m     109 x6D o155 |
     01110 |  *SO    14 x0E o016 | .      46 x2E o056 | N      78 x4E o116 | n     110 x6E o156 |
     01111 |  *SI    15 x0F o017 | /      47 x2F o057 | O      79 x4F o117 | o     111 x6F o157 |
     10000 |  *DLE   16 x10 o020 | 0      48 x30 o060 | P      80 x50 o120 | p     112 x70 o160 |
     10001 |  *DC1   17 x11 o021 | 1      49 x31 o061 | Q      81 x51 o121 | q     113 x71 o161 |
     10010 |  *DC2   18 x12 o022 | 2      50 x32 o062 | R      82 x52 o122 | r     114 x72 o162 |
     10011 |  *DC3   19 x13 o023 | 3      51 x33 o063 | S      83 x53 o123 | s     115 x73 o163 |
     10100 |  *DC4   20 x14 o024 | 4      52 x34 o064 | T      84 x54 o124 | t     116 x74 o164 |
     10101 |  *NAK   21 x15 o025 | 5      53 x35 o065 | U      85 x55 o125 | u     117 x75 o165 |
     10110 |  *SYN   22 x16 o026 | 6      54 x36 o066 | V      86 x56 o126 | v     118 x76 o166 |
     10111 |  *ETB   23 x17 o027 | 7      55 x37 o067 | W      87 x57 o127 | w     119 x77 o167 |
     11000 |  *CAN   24 x18 o030 | 8      56 x38 o070 | X      88 x58 o130 | x     120 x78 o170 |
     11001 |  *EM    25 x19 o031 | 9      57 x39 o071 | Y      89 x59 o131 | y     121 x79 o171 |
     11010 |  *SUB   26 x1A o032 | :      58 x3A o072 | Z      90 x5A o132 | z     122 x7A o172 |
     11011 |  *ESC   27 x1B o033 | ;      59 x3B o073 | [      91 x5B o133 | {     123 x7B o173 |
     11100 |  *FS    28 x1C o034 | <      60 x3C o074 | \      92 x5C o134 | |     124 x7C o174 |
     11101 |  *GS    29 x1D o035 | =      61 x3D o075 | ]      93 x5D o135 | }     125 x7D o175 |
     11110 |  *RS    30 x1E o036 | >      62 x3E o076 | ^      94 x5E o136 | ~     126 x7E o176 |
     11111 |  *US    31 x1F o037 | ?      63 x3F o077 | _      95 x5F o137 | *DEL  127 x7F o177 |
    
     msb ->           100        |         101        |         110        |         111        |
     00000 |  Ç     128 x80 o200 | á     160 xA0 o240 | └     192 xC0 o300 | α     224 xE0 o340 |
     00001 |  ü     129 x81 o201 | í     161 xA1 o241 | ┴     193 xC1 o301 | ß     225 xE1 o341 |
     00010 |  é     130 x82 o202 | ó     162 xA2 o242 | ┬     194 xC2 o302 | Γ     226 xE2 o342 |
     00011 |  â     131 x83 o203 | ú     163 xA3 o243 | ├     195 xC3 o303 | π     227 xE3 o343 |
     00100 |  ä     132 x84 o204 | ñ     164 xA4 o244 | ─     196 xC4 o304 | Σ     228 xE4 o344 |
     00101 |  à     133 x85 o205 | Ñ     165 xA5 o245 | ┼     197 xC5 o305 | σ     229 xE5 o345 |
     00110 |  å     134 x86 o206 | ª     166 xA6 o246 | ╞     198 xC6 o306 | µ     230 xE6 o346 |
     00111 |  ç     135 x87 o207 | º     167 xA7 o247 | ╟     199 xC7 o307 | τ     231 xE7 o347 |
     01000 |  ê     136 x88 o210 | ¿     168 xA8 o250 | ╚     200 xC8 o310 | Φ     232 xE8 o350 |
     01001 |  ë     137 x89 o211 | ⌐     169 xA9 o251 | ╔     201 xC9 o311 | Θ     233 xE9 o351 |
     01010 |  è     138 x8A o212 | ¬     170 xAA o252 | ╩     202 xCA o312 | Ω     234 xEA o352 |
     01011 |  ï     139 x8B o213 | ½     171 xAB o253 | ╦     203 xCB o313 | δ     235 xEB o353 |
     01100 |  î     140 x8C o214 | ¼     172 xAC o254 | ╠     204 xCC o314 | ∞     236 xEC o354 |
     01101 |  ì     141 x8D o215 | ¡     173 xAD o255 | ═     205 xCD o315 | φ     237 xED o355 |
     01110 |  Ä     142 x8E o216 | «     174 xAE o256 | ╬     206 xCE o316 | ε     238 xEE o356 |
     01111 |  Å     143 x8F o217 | »     175 xAF o257 | ╧     207 xCF o317 | ∩     239 xEF o357 |
     10000 |  É     144 x90 o220 | ░     176 xB0 o260 | ╨     208 xD0 o320 | ≡     240 xF0 o360 |
     10001 |  æ     145 x91 o221 | ▒     177 xB1 o261 | ╤     209 xD1 o321 | ±     241 xF1 o361 |
     10010 |  Æ     146 x92 o222 | ▓     178 xB2 o262 | ╥     210 xD2 o322 | ≥     242 xF2 o362 |
     10011 |  ô     147 x93 o223 | │     179 xB3 o263 | ╙     211 xD3 o323 | ≤     243 xF3 o363 |
     10100 |  ö     148 x94 o224 | ┤     180 xB4 o264 | ╘     212 xD4 o324 | ⌠     244 xF4 o364 |
     10101 |  ò     149 x95 o225 | ╡     181 xB5 o265 | ╒     213 xD5 o325 | ⌡     245 xF5 o365 |
     10110 |  û     150 x96 o226 | ╢     182 xB6 o266 | ╓     214 xD6 o326 | ÷     246 xF6 o366 |
     10111 |  ù     151 x97 o227 | ╖     183 xB7 o267 | ╫     215 xD7 o327 | ≈     247 xF7 o367 |
     11000 |  *     152 x98 o230 | ╕     184 xB8 o270 | ╪     216 xD8 o330 | °     248 xF8 o370 |
     11001 |  Ö     153 x99 o231 | ╣     185 xB9 o271 | ┘     217 xD9 o331 | ∙     249 xF9 o371 |
     11010 |  Ü     154 x9A o232 | ║     186 xBA o272 | ┌     218 xDA o332 | ·     250 xFA o372 |
     11011 |  ¢     155 x9B o233 | ╗     187 xBB o273 | █     219 xDB o333 | √     251 xFB o373 |
     11100 |  £     156 x9C o234 | ╝     188 xBC o274 | ▄     220 xDC o334 | ⁿ     252 xFC o374 |
     11101 |  ¥     157 x9D o235 | ╜     189 xBD o275 | ▌     221 xDD o335 | ²     253 xFD o375 |
     11110 |  ₧     158 x9E o236 | ╛     190 xBE o276 | ▐     222 xDE o336 | ■     254 xFE o376 |
     11111 |  ƒ     159 x9F o237 | ┐     191 xBF o277 | ▀     223 xDF o337 | *NBSP 255 xFF o377 |
    
    Encoding: OEM United States IBM437 
    Note: * indicates characters that are non-printing (not visible).
    
    Control Characters
      to send       press simultaneously
     *NUL    0      CTRL @
     *SOH    1      CTRL A
     *STX    2      CTRL B
     *ETX    3      CTRL C
     *EOT    4      CTRL D
     *ENQ    5      CTRL E
     *ACK    6      CTRL F
     *BEL    7      CTRL G
     *BS     8      CTRL H
     *HT     9      CTRL I
     *LF    10      CTRL J
     *VT    11      CTRL K
     *FF    12      CTRL L
     *CR    13      CTRL M
     *SO    14      CTRL N
     *SI    15      CTRL O
     *DLE   16      CTRL P
     *DC1   17      CTRL Q
     *DC2   18      CTRL R
     *DC3   19      CTRL S
     *DC4   20      CTRL T
     *NAK   21      CTRL U
     *SYN   22      CTRL V
     *ETB   23      CTRL W
     *CAN   24      CTRL X
     *EM    25      CTRL Y
     *SUB   26      CTRL Z
     *ESC   27      CTRL [
     *FS    28      CTRL \
     *GS    29      CTRL ]
     *RS    30      CTRL ^
     *US    31      CTRL _
    Last edited by dbasnett; May 25th, 2015 at 11:05 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width