how to show incoming binary data as hex values

This is a discussion on how to show incoming binary data as hex values within the C# Programming forums, part of the General Programming Boards category; i have porgram that is data reading via usb.. i have to check with diff devices ...have diff buffer size(so ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    how to show incoming binary data as hex values

    i have porgram that is data reading via usb..
    i have to check with diff devices ...have diff buffer size(so cant be fixed).
    i send comand to read fone and i get result in binary..
    currently am converting it in string..
    but i need those as hex values...

    comand

    Code:
    Byte[] sp ={0x1B, 0x00, 0x10, 0x53, 0x00, 0x05, 0x00, 0x0F,
    0x03, 0x12, 0x0D};
    result

    Code:
    string spp = read_write_str(deviceHandle, sp, sp.Length);
    Thread.Sleep(100);
    
    richTextBox2.Text += spp
    also how to undefien buffer size...

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,664
    Code:
    StringBuilder sb = new StringBuilder();
    foreach (var b in sp)
    {
        sb.AppendFormat("{0:x2}", b);
    }
    Console.WriteLine(sb.ToString());

  3. #3
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Alternative:

    Code:
    Console.WriteLine(BitConvertor.ToString(sp));

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,615
    richynaughty: because of your post in this thread, I am going to give you the benefit of the doubt that you are not a spam bot. However, stop placing links as you sign off; use the signature forum functionality instead.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    thnks to every one i resolve issue by delclaring function same like string ..
    bec need to define buffer size too..
    now one more thing i need to do i need to split hex data..
    mean need to use only parts from whole data ..
    how to do that..

  6. #6
    Registered User
    Join Date
    Mar 2009
    Location
    england
    Posts
    209
    Code:
    static String[] ByteArray2HexArray(byte[] buf)
    {
        return BitConvertor.ToString(buf).Split(new String[] { "-" }, StringSplitOptions.None);
    }
    Something like this would return an array of hex values (of the same length as your original byte array, of course). I am assuming this is what you mean?

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    Code:
    1B10005300500F4A03131155FFFFFF FFFFFFFFFFFFFFFFFF
    FFFFFFFF003880000000000000002341500000000000018
    0100000000000020000001FFFFFF000000007FFF6F07FFFF
    FFFFF80000340300050223415FFF
    i have like this data and need these ones to separate from this..
    i need only to display colored values in diff text boxes..

  8. #8
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,664

  9. #9
    Registered User
    Join Date
    Mar 2010
    Posts
    4
    Quote Originally Posted by rags_to_riches View Post
    ??????????????

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Replies: 0
    Last Post: 11-04-2006, 10:07 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21