Why get the Registry value is -1 but no 0xFFFFFFFF(4294967295)?

  • Thread starter Thread starter YXQ
  • Start date Start date
Y

YXQ

I want to get the Registry value, the value is 0xFFFFFFFF(4294967295), but
get the value is -1 using Getvalue method, why? thank you.
 
Are you using an Integer (Int32), the maximum positive value of that is
2147483647

Therefore with a simple Int32 you can by instance not address (calculate)
memory addresses above the 2Gb

Cor
 
YXQ said:
I want to get the Registry value, the value is
0xFFFFFFFF(4294967295), but get the value is -1 using Getvalue
method, why? thank you.

The bits which represent 4294967295 in a UInt32 are the same bits which
represent -1 in an Int32:

Dim a As Int32 = -1
Dim b As UInt32
b = BitConverter.ToUInt32(BitConverter.GetBytes(a), 0)
Console.WriteLine(a)
Console.WriteLine(b)

Outputs:
-1
4294967295

Andrew
 
yxq said:
Thank you, but i do not understand when need to convert the value.
My code:
/////////////////////////////////////////////////
Dim objrk As RegistryKey =
Registry.CurrentUser.OpenSubKey("test") Dim a As Int32 =
objrk.GetValue("name") Dim b As UInt32 =
BitConverter.ToUInt32(BitConverter.GetBytes(a), 0)
MessageBox.Show(a) MessageBox.Show(b)
////////////////////////////////////////////////
The b value always is right. If the value is small, a and b are right
both, if the value is big, a will be wrong.
Do i need add the code BitConverter.ToUInt32 to my program? because i
do not know how many the value is...

What is being stored in the registry? For example, if you are storing a
DWord (32-bit value) then you are responsible for how you interpret those 32
bits. If you stored them as a UInt32 then you need to get them back into a
variable with a type of UInt32. What happens if you read the registry value
directly into a variable of type UInt32?

Andrew
 
YXQ said:
I want to get the Registry value, the value is 0xFFFFFFFF(4294967295), but
get the value is -1 using Getvalue method, why? thank you.

For a signed 32-bit integer '&HFFFFFFFF' is the bit representation of the
value -1:

\\\
Dim i As Integer = &HFFFFFFFF
MsgBox(i) ' -1.
///
 
Back
Top