none
C# Converting an integer or string to number of bytes RRS feed

All replies

  • Have you used Convert.ToByte

    https://docs.microsoft.com/en-us/dotnet/api/system.convert.tobyte?view=netframework-4.8


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Friday, March 6, 2020 4:46 PM
    Moderator
  • Hi Krishna90,
    As Kareninstructor said, you can use Convert.ToByte method to convert a specified value to an 8-bit unsigned integer.
    And you can use Convert.ToUInt64 method to convert a specified value to ulong.
    Here is a code example you can refer to.

    String s = "101";
    byte b=Convert.ToByte(s);
    ulong result = Convert.ToUInt64(s);

    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 9, 2020 9:41 AM
  • Hello friend

    var buffer = (UInt8)(value)


    Monday, March 9, 2020 11:32 AM
  • > var buffer = (UInt8)(value)

    What do you think that's going to do?  Did you try it with his data?


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, March 9, 2020 5:21 PM
  • What are you expecting the result to be?  Are those binary bits, decimal digits, or hex digits?  So, do you want the result to be decimal 5 or decimal 101 or decimal 257?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Monday, March 9, 2020 5:22 PM
  • Hi Krishna90,
    Has your problem been solved? If it is resolved, we suggest that you mark it as the answer. So it can help other people who have the same problem find a solution quickly. If not solved, what problem did you encounter?
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 12, 2020 9:03 AM