Hexadecimal Question

The code below (in VB) writes a hexidecimal number to a registry location. Can someone please tell me the equivalent hex representation in C#  I put a couple of the lines that I tried below, but that didn't quite work right. When the value in the registry is correctly set, the C# code works (registry should be all "F's" which returns "-1"). The problem is that I cannot use a string to set this registry value, if I do it will change the type from REG_DWORD to REG_SZ and destroy the integrity of the registry.  I need to be able to pass that value (FFFFFFFF) without using a string, which I successfully accomplished using the VB code below.  Is there a C# equivalent to "&H"   Thanks in advance.

-jk
 VB (works correctly)


value = regKey.GetValue("Retention")
If value <> "ffffffff" Then
      ListBox1.Items.Add("Event log for security set to overwrite log entries")
      regKey.SetValue("Retention", &HFFFFFFFF)
      ListBox1.Items.Add("--------Policy corrected. Set to not overwrite log entries")

 


C#  

value = regKey.GetValue("Retention").ToString();
         if (value != "-1")
         {
            sw.WriteLine("Event log for security set to overwrite log entries");
            regKey.SetValue("Retention", 0xFFFFFFFF);
            sw.WriteLine("--------Policy corrected. Set to not overwrite log entries");
         }

 




Answer this question

Hexadecimal Question

  • Sooraj B

    The problem in the C# case is that 0xFFFFFFFF is an unsigned integer. So it evaluates to 4294967295 rather than -1. Given that an integer is an integer no matter how you assign its value, why not write:

    value = regKey.GetValue("Retention");
    if (value != -1)
    {
      sw.WriteLine("Event log for security set to overwrite log entries");
      regKey.SetValue("Retention", -1);
      sw.WriteLine("--------Policy corrected. Set to not overwrite log entries");
    }


  • Yosi345

    Thanks James, I actually figured it out just before I read your post, and my code is exactly like the piece you posted.  Thanks again.
  • Hexadecimal Question