views:

41

answers:

1

hi

I have some php code as below.

<?php
    $value = -1924050635;
    echo "before:".$value;
    echo "<br/>";
    $value = sprintf('%u', $value);
        echo "<br/>";
    echo "after:".$value;

?>

Before value is -1924050635

after value is 2370916661

My problem is that what the sprintf is doing here.

What i need to do if i want the above same php functionality in VB.Net.

+1  A: 

The php integer type is always signed (and in your case 32 bit wide). I.e. you let sprintf(%u) interpret the bit/bye sequence of a signed integer as an unsigned integer. You can do something similar in VB.Net by using the class System.BitConverter to get the byte() representation of the signed integer and then create an unsigned integer from that sequence.

Module Module1
  Sub Main()
    Dim x As Integer = -1924050635
    Dim y As UInteger = BitConverter.ToUInt32(BitConverter.GetBytes(x), 0)
    System.Console.Write("y=" & y)
  End Sub
End Module

prints y=2370916661

(I'm not a VB.Net expert - there might be simpler solutions)

VolkerK
Excellent answer Volker, thx
Avinash