Jump to content
Sign in to follow this  
Sergio990

Passar valores de Bits para string [RESOLVIDO]

Recommended Posts

Sergio990

Boas,

Eu tenho um valor em bits, mas preciso de uma função que me transforme os bits no numero, alguém sabe como o fazer?

Agradecia imenso ;)

Share this post


Link to post
Share on other sites
Sergio990
    public string IpBitsToString(uint ip)
    {
        uint na = ip >> 24;
        uint n1 = na << 24;
        
        uint r2 = ip - n1;
        uint nb = r2 >> 16;
        uint n2 = nb << 16;

        uint r3 = ip - n1 - n2;
        uint nc = r3 >> 8;
        uint n3 = nc << 8;

        uint r4 = ip - n1 - n2 - n3;
        uint nd = r4;

        string n1a = Convert.ToString(na);
        string n2b = Convert.ToString(nb);
        string n3c = Convert.ToString(nc);
        string n4d = Convert.ToString(nd);
        
        string resultado = string.Concat(n1a, ".",n2b,".",n3c,".",n4d); 
        return resultado;
    }

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.