2

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 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.