Convert string to byte (not byte array) and store on RFID Tag RRS feed

  • Question

  • User368453303 posted

    Good day everyone:

    I am develping an application that integrates with an RFID kit. The problem is, the kit comes with an .cs class that accepts data stored in a byte array however, each information stored in the array respresents an int. I wanted to store String information in each array but, my research suggest that a String itself can be converted to a byte array and not a byte....here the code from the .cs class:

    byte BlockNo = 0;
    byte[] BlockData = new byte[16];
    byte ReturnCode = 0;
    BlockNo = byte.Parse(cmb_RWBlockNo.Text);
    BlockData[0] = byte.Parse(t_B1.Text, System.Globalization.NumberStyles.HexNumber);
    BlockData[1] = byte.Parse(t_B2.Text, System.Globalization.NumberStyles.HexNumber);
    BlockData[2] = byte.Parse(t_B3.Text, System.Globalization.NumberStyles.HexNumber);
    BlockData[3] = byte.Parse(t_B4.Text, System.Globalization.NumberStyles.HexNumber);
    BlockData[4] = byte.Parse(t_B5.Text, System.Globalization.NumberStyles.HexNumber);
    BlockData[5] = byte.Parse(t_B6.Text, System.Globalization.NumberStyles.HexNumber);
    BlockData[6] = byte.Parse(t_B7.Text, System.Globalization.NumberStyles.HexNumber);




    BlockData[15] = byte.Parse(t_B15.Text, System.Globalization.NumberStyles.HexNumber);

    Each t_b*.text respresents an int. Is there a way I can stored a String in a single byte block? 

    Saturday, May 8, 2010 4:36 PM


  • User-1827453801 posted

    Each character of a string is a 'char'. A char can be represented as a byte (or something larger). So unless your "string" is only one char long you're going to need a byte array to hold it.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, May 9, 2010 2:56 AM