php ve vb.net değişken dönüşüm ve anlamlandırma

1 Cevap php

Ben aşağıdaki gibi bazı php kodu var.

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

?>

Değer önce -1924050635

değeri sonra 2370916661

Benim sorunum sprintf burada ne yapıyor olmasıdır.

I VB.Net Yukarıdaki aynı php özelliğe isterseniz ben ne yapmak gerekir.

1 Cevap

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

baskılar y=2370916661

(Ben bir VB.Net uzman değilim - basit çözümler olabilir)