IP to Hex

IP Address Input
Sample
Hex Output

IP to Hex Converter - Free Online Tool

IP to Hex Converter is a free online tool that allows you to convert IP addresses to hexadecimal numbers. This tool is designed to be easy to use and doesn't require any system or software dependencies. With this tool, you can quickly convert IP addresses to hex format without any hassle.

Features

  • Free and online
  • No system and software dependencies
  • Can Clear,Can Copy,Have Sample
  • Data security, local computing

How to Use

To use the IP to Hex Converter, simply follow the steps below:

  1. Input or paste your IP address in the input box.
  2. Click the "Convert" button to convert your IP address to a hexadecimal number.
  3. The converted hexadecimal number will be displayed in the output box.
  4. You can now copy the converted hexadecimal number or click the "Copy" button.

Example Codes

Here are some example codes in Python, C, C++, JavaScript, Java, and PHP that you can use to convert IP addresses to hexadecimal numbers.

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;

Using the IP to Hex Converter is easy and straightforward. With this free online tool, you can convert IP addresses to hexadecimal numbers without any hassle. The tool is also secure, as it performs all computations locally, ensuring that your data is safe. So, try out the IP to Hex Converter today and start converting your IP addresses to hexadecimal numbers with ease!

Frequently Asked Questions (FAQ)

Meet our more Tools