C# Int to Hex of the Int (Application)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BageDevimo
    New Member
    • Jul 2008
    • 10

    C# Int to Hex of the Int (Application)

    Hiya

    Ok, so im writing a program that requires the hex of the int.. but not just this:
    Code:
     int myInt = 24;
     string myHex = myInt.ToString("X");
    'cause that'll just return 0x18, which is just the same as me going:
    Code:
    int myInt = 0x18;
    Im after the 4 (maybe 8?) bytes of the int, that are stored in memory. How can I get at these?

    Thanks!
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    So you want 0x0018 (int16) or 0x00000018(int3 2) as a string value?
    If you don't want the string value but want a byte[] then consider this:
    [code=c#]
    byte[] mybytes=BitConv erter.GetBytes( myInt);
    [/code]

    Comment

    • BageDevimo
      New Member
      • Jul 2008
      • 10

      #3
      Ok, so the Int32 one is just the equvilent of 00 00 00 18 or something, right?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Yeah
        0x18 is the same number as 0x0018 or 0x0000000000000 018 or whatever

        Comment

        • BageDevimo
          New Member
          • Jul 2008
          • 10

          #5
          Ok, cool..

          I've got it working, thanks a lot!

          I used BitConverter.To Int32() to get it back to a int also!!

          Ben Anderson,

          Comment

          Working...