none
Decode image.jpg to Binary numbers like 01001001-01001001 RRS feed

  • Question

  • For example i have image.jpg and i want to view the binary code of that file what to do?

    expected out put: 01010011-00101100

    how to do this in VB.net windows form application?

    Thursday, August 27, 2015 6:13 PM

Answers

  • If the difference from your previous question is that you simply want to separate the bytes with a "-", then you can use this code.

    Dim bytes() As Byte = IO.File.ReadAllBytes(filePath) 'Read the file
    Dim sb As New System.Text.StringBuilder
    Dim sep As String = ""
    For Each b As Byte In bytes
        sb.Append(sep)
        sep = "-"
        sb.Append(Convert.ToString(b, 2).PadLeft(8, "0"c))
    Next
    Dim s As String = sb.ToString 

    • Marked as answer by MetalZERO-1 Thursday, August 27, 2015 7:17 PM
    Thursday, August 27, 2015 6:41 PM

All replies

  • You can do it like this:

    Dim data() as Byte = File.ReadAllBytes(path) // path of your image

    Dim builder AsNew System.Text.StringBuilder

    For Each item As Byte In data

    builder.Append(item.ToString)

    // you have the Stringbuilder and convert to String to show in a textbox

    result as String = builder.ToString

     



    • Edited by Val10 Thursday, August 27, 2015 6:37 PM
    • Marked as answer by MetalZERO-1 Thursday, August 27, 2015 7:17 PM
    • Unmarked as answer by MetalZERO-1 Thursday, August 27, 2015 7:18 PM
    Thursday, August 27, 2015 6:37 PM
  • If the difference from your previous question is that you simply want to separate the bytes with a "-", then you can use this code.

    Dim bytes() As Byte = IO.File.ReadAllBytes(filePath) 'Read the file
    Dim sb As New System.Text.StringBuilder
    Dim sep As String = ""
    For Each b As Byte In bytes
        sb.Append(sep)
        sep = "-"
        sb.Append(Convert.ToString(b, 2).PadLeft(8, "0"c))
    Next
    Dim s As String = sb.ToString 

    • Marked as answer by MetalZERO-1 Thursday, August 27, 2015 7:17 PM
    Thursday, August 27, 2015 6:41 PM
  • ahahaha sorry for repeated question, you already answered my question. thanks alot
    Thursday, August 27, 2015 7:05 PM