Convert c# to php

sami37

New Member
Sep 29, 2016
2
0
Hello,

i currently got a c# code that i want to convert to php, but i got a part that i don't know how to convert.
how i can convert this c# code to php

Console.WriteLine("Variance : " + variance);
while (variance > 0)
{
var stat = (byte)(variance & 0x1f);
variance >>= 5;

stats.Add(stat);
}
i am blocked at the "variance >>= 5;"
 

griimnak

You're a slave to the money then you die
Jul 20, 2013
957
800
<?php
print( "Variance:", $variance);
while ($variance > 0) {
$stat = "i don't know what you're trying to do here";
$variance >>= 5;

//function addStat(); here
}
?>

variance >>= 5; equivilent in php is variance > 5 i think.. not sure i'm very rusty
 

sami37

New Member
Sep 29, 2016
2
0
Thanks for reply,

Here is the fully program

Code:
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{
    class Program
    {
        private const byte ShieldDurabilitySlot = 0,
                           ShieldPhySpecSlot = 1,
                           ShieldMagSpecSlot = 2,
                           ShieldBlockRatioSlot = 3,
                           ShieldPhyDefSlot = 4,
                           ShieldMagDefSlot = 5;

        private const byte ArmorDurabilitySlot = 0,
                           ArmorPhySpecSlot = 1,
                           ArmorMagSpecSlot = 2,
                           ArmorPhyDefSlot = 3,
                           ArmorMagDefSlot = 4,
                           ArmorEvasionRatioSlot = 5;

        private const byte WeaponDurabilitySlot = 0,
                           WeaponPhySpecSlot = 1,
                           WeaponMagSpecSlot = 2,
                           WeaponHitRatioSlot = 3,
                           WeaponPhyDmgSlot = 4,
                           WeaponMagDmgSlot = 5,
                           WeaponCritSlot = 6;

        private const byte AccessoryPhyAbsorpSlot = 0,
                           AccessoryMagAbsorpSlot = 1;

        static void Main()
        {
            const ulong variance = 20401094656;
            DisplayVariance(variance);

            Console.ReadLine();
        }

        static void DisplayVariance(ulong variance)
        {
            var stats = new List<byte>();

            Console.WriteLine("Variance : " + variance);
            while (variance > 0)
            {
                var stat = (byte)(variance & 0x1f);
                variance >>= 5;

                stats.Add(stat);
            }
            switch (stats.Count)
            {
                case 2:
                    //Accessory
                    Console.WriteLine("Accessory : AccessoryPhyAbsorpSlot " + ToPercentage(stats[AccessoryPhyAbsorpSlot]));
                    Console.WriteLine("Accessory : AccessoryMagAbsorpSlot " + ToPercentage(stats[AccessoryMagAbsorpSlot]));
                    break;
                case 6:
                    //Equip
                    //NOTE this can also be a shield !
                    Console.WriteLine("equip : ArmorPhyDefSlot " + ToPercentage(stats[ArmorPhyDefSlot]));
                    Console.WriteLine("equip : ArmorMagDefSlot " + ToPercentage(stats[ArmorMagDefSlot]));
                    Console.WriteLine("equip : ArmorDurabilitySlot " + ToPercentage(stats[ArmorDurabilitySlot]));
                    Console.WriteLine("equip : ArmorEvasionRatioSlot " + ToPercentage(stats[ArmorEvasionRatioSlot]));
                    Console.WriteLine("equip : ArmorPhySpecSlot " + ToPercentage(stats[ArmorPhySpecSlot]));
                    Console.WriteLine("equip : ArmorMagSpecSlot " + ToPercentage(stats[ArmorMagSpecSlot]));
                    break;
                case 7:
                    //Weapon
                    Console.WriteLine("Weapon : WeaponPhyDmgSlot " + ToPercentage(stats[WeaponPhyDmgSlot]));
                    Console.WriteLine("Weapon : WeaponMagDmgSlot " + ToPercentage(stats[WeaponMagDmgSlot]));
                    Console.WriteLine("Weapon : WeaponDurabilitySlot " + ToPercentage(stats[WeaponDurabilitySlot]));
                    Console.WriteLine("Weapon : WeaponHitRatioSlot " + ToPercentage(stats[WeaponHitRatioSlot]));
                    Console.WriteLine("Weapon : WeaponCritSlot " + ToPercentage(stats[WeaponCritSlot]));
                    Console.WriteLine("Weapon : WeaponPhySpecSlot " + ToPercentage(stats[WeaponPhySpecSlot]));
                    Console.WriteLine("Weapon : WeaponMagSpecSlot " + ToPercentage(stats[WeaponMagSpecSlot]));
                    break;
                default:
                    Console.WriteLine("{0} stats... wtf?", stats.Count);
                    break;
            }
        }

        private static string ToPercentage(byte stat)
        {
            return String.Format("{0}%", stat * 100 / 31);
        }
    }
}
The result when i start it is here :

download.php

I need the same code/result in php.
I already convert most of this code to php but the part i show....


That my actual php code with the missing part

PHP:
<?php
    $ShieldDurabilitySlot = 0;
    $ShieldPhySpecSlot = 1;
    $ShieldMagSpecSlot = 2;
    $ShieldBlockRatioSlot = 3;
    $ShieldPhyDefSlot = 4;
    $ShieldMagDefSlot = 5;

    $ArmorDurabilitySlot = 0;
    $ArmorPhySpecSlot = 1;
    $ArmorMagSpecSlot = 2;
    $ArmorPhyDefSlot = 3;
    $ArmorMagDefSlot = 4;
    $ArmorEvasionRatioSlot = 5;

    $WeaponDurabilitySlot = 0;
    $WeaponPhySpecSlot = 1;
    $WeaponMagSpecSlot = 2;
    $WeaponHitRatioSlot = 3;
    $WeaponPhyDmgSlot = 4;
    $WeaponMagDmgSlot = 5;
    $WeaponCritSlot = 6;

    $AccessoryPhyAbsorpSlot = 0;
    $AccessoryMagAbsorpSlot = 1;

    $variance = 20401094656;
    DisplayVariance($variance);

    function DisplayVariance($variance)
    {
        $stats = array();

        echo "Variance : ".$variance;
        while ($variance > 0)
        {
            $stat = ($variance & 31);
            $variance >>= 5;

            $stats[] = $stat;
        }
        for($i = 0; $i < count($stats); $i++)
        switch($stats[$i])
        {
            case 2:
                //Accessory
                echo "Accessory : AccessoryPhyAbsorpSlot ".ToPercentage($stats[$AccessoryPhyAbsorpSlot]);
                echo "Accessory : AccessoryMagAbsorpSlot ".ToPercentage($stats[$AccessoryMagAbsorpSlot]);
                break;
            case 6:
                //Equip
                //NOTE this can also be a shield !
                echo "equip : ArmorPhyDefSlot " + ToPercentage($stats[$ArmorPhyDefSlot]);
                echo "equip : ArmorMagDefSlot " + ToPercentage($stats[$ArmorMagDefSlot]);
                echo "equip : ArmorDurabilitySlot " + ToPercentage($stats[$ArmorDurabilitySlot]);
                echo "equip : ArmorEvasionRatioSlot " + ToPercentage($stats[$ArmorEvasionRatioSlot]);
                echo "equip : ArmorPhySpecSlot " + ToPercentage($stats[$ArmorPhySpecSlot]);
                echo "equip : ArmorMagSpecSlot " + ToPercentage($stats[$ArmorMagSpecSlot]);
                break;
            case 7:
                //Weapon
                echo "Weapon : WeaponPhyDmgSlot " + ToPercentage($stats[$WeaponPhyDmgSlot]);
                echo "Weapon : WeaponMagDmgSlot " + ToPercentage($stats[$WeaponMagDmgSlot]);
                echo "Weapon : WeaponDurabilitySlot " + ToPercentage($stats[$WeaponDurabilitySlot]);
                echo "Weapon : WeaponHitRatioSlot " + ToPercentage($stats[$WeaponHitRatioSlot]);
                echo "Weapon : WeaponCritSlot " + ToPercentage($stats[$WeaponCritSlot]);
                echo "Weapon : WeaponPhySpecSlot " + ToPercentage($stats[$WeaponPhySpecSlot]);
                echo "Weapon : WeaponMagSpecSlot " + ToPercentage($stats[$WeaponMagSpecSlot]);
                break;
            default:
                echo $stats[$i]." stats... wtf?";
                break;
        }
    }

    function ToPercentage($stat)
    {
        return ($stat * 100 / 31).'%';
    }
 
Hello,

I reply to this topic because a friend solved the problem, it was from outdated php version.

Thanks anyway for your help.
 

Users who are viewing this thread

Top