IP a Hex

Entrada de dirección IP
Ejemplo
Salida en Hex

Convertidor de IP a Hexadecimal - Herramienta en línea gratuita

El Convertidor de IP a Hexadecimal es una herramienta en línea gratuita que le permite convertir direcciones IP en números hexadecimales. Esta herramienta está diseñada para ser fácil de usar y no requiere dependencias de sistema o software. Con esta herramienta, puede convertir rápidamente direcciones IP al formato hexadecimal sin ningún problema.

Características

  • Gratis y en línea
  • Sin dependencias de sistema y software
  • Puede borrar, copiar y tiene muestra
  • Seguridad de datos, cómputo local

Cómo usar

Para usar el Convertidor de IP a Hexadecimal, simplemente siga los siguientes pasos:

  1. Ingrese o pegue su dirección IP en el cuadro de entrada.
  2. Haga clic en el botón "Convertir" para convertir su dirección IP en un número hexadecimal.
  3. El número hexadecimal convertido se mostrará en el cuadro de salida.
  4. Ahora puede copiar el número hexadecimal convertido o hacer clic en el botón "Copiar".

Ejemplos de códigos

Aquí hay algunos ejemplos de códigos en Python, C, C ++, JavaScript, Java y PHP que puede usar para convertir direcciones IP en números hexadecimales.

Python

def ip_to_hex(ip_address):
    octets = ip_address.split(".")
    hex_ip = ""
    for octet in octets:
        hex_ip += hex(int(octet))[2:].zfill(2)
    return hex_ip

# Example usage:
ip_address = "127.0.0.1"
hex_ip = ip_to_hex(ip_address)
print(hex_ip)

C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char *ip_to_hex(char *ip_address)
{
    char *octet;
    char *hex_ip = (char *)malloc(sizeof(char) * 8);
    hex_ip[0] = '0';
    hex_ip[1] = 'x';
    for (int i = 0; i < 4; i++)
    {
        octet = strtok(ip_address, ".");
        ip_address = NULL;
        strcat(hex_ip, strtol(octet, NULL, 10) < 16 ? "0" : "");
        sprintf(hex_ip + strlen(hex_ip), "%X", strtol(octet, NULL, 10));
    }
    return hex_ip;
}

// Example usage:
int main()
{
    char *ip_address = "127.0.0.1";
    char *hex_ip = ip_to_hex(ip_address);
    printf("%s\n", hex_ip);
    free(hex_ip);
    return 0;
}

C++

#include <iostream>
#include <sstream>
#include <iomanip>

std::string ip_to_hex(std::string ip_address) {
    std::stringstream hex_ip;
    hex_ip << "0x";
    int octet1, octet2, octet3, octet4;
    char delimiter;
    std::stringstream ss(ip_address);
    ss >> octet1 >> delimiter >> octet2 >> delimiter >> octet3 >> delimiter >> octet4;

    hex_ip << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << octet1;
    hex_ip << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << octet2;
    hex_ip << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << octet3;
    hex_ip << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << octet4;

    return hex_ip.str();
}

// Example usage:
int main() {
    std::string ip_address = "127.0.0.1";
    std::string hex_ip = ip_to_hex(ip_address);
    std::cout << hex_ip << std::endl;
    return 0;
}

JavaScript

function ipToHex(ipAddress) {
  let octets = ipAddress.split(".");
  let hexIp = "0x";
  for (let i = 0; i < octets.length; i++) {
    hexIp += parseInt(octets[i]).toString(16).padStart(2, "0");
  }
  return hexIp;
}

// Example usage:
let ipAddress = "127.0.0.1";
let hexIp = ipToHex(ipAddress);
console.log(hexIp);

Java

public static String ipToHex(String ipAddress) {
    String[] octets = ipAddress.split("\\.");
    String hexIp = "0x";
    for (String octet : octets) {
        hexIp += Integer.toHexString(Integer.parseInt(octet)).toUpperCase();
    }
    return hexIp;
}

// Example usage:
String ipAddress = "127.0.0.1";
String hexIp = ipToHex(ipAddress);
System.out.println(hexIp);

PHP

function ip_to_hex($ip_address) {
    $octets = explode(".", $ip_address);
    $hex_ip = "0x";
    foreach ($octets as $octet) {
        $hex_ip .= str_pad(dechex($octet), 2, "0", STR_PAD_LEFT);
    }
    return $hex_ip;
}

// Example usage:
$ip_address = "127.0.0.1";
$hex_ip = ip_to_hex($ip_address);
echo $hex_ip;

Usar el Convertidor de IP a Hexadecimal es fácil y sencillo. Con esta herramienta en línea gratuita, puede convertir direcciones IP en números hexadecimales sin ningún problema. La herramienta también es segura, ya que realiza todos los cálculos localmente, asegurando que sus datos estén seguros. ¡Así que pruebe el Convertidor de IP a Hexadecimal hoy y comience a convertir sus direcciones IP en números hexadecimales con facilidad!

Preguntas frecuentes (FAQ)

Conoce nuestras herramientas adicionales