English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Given the byte array advertisement, the task is to convert it to an IP address using the IPAddress class in Java and display the result.
A byte consists of8bits composed of, a byte array is composed of multiple consecutive bytes, which store binary information. In Java, byte is a primitive data type that can be understood as the byte of a computer, that is,8bits, can save-128To127Value.
Declare a byte-byte name_of_byte_variable = initial_value;
Declare a byte array-byte[] name_of_byte_array = new byte[];
In Java, the IPAddress class is used to get the IP address of any system. It exists in the System.Net class and needs to be imported to use the IPAddress class.
IPAddress ObjectName = new IPAddress(byte[])
Input-: 171, 32, 101, 11 Output-: 171.32.101.11 Input-: 172, 31, 102, 14 Output-: 172.31.102.14
The methods we use in the following program are as follows-
Import class System.net
Enter numbers as bytes in the byte array
Create an IPAddress class object and pass an array of bytes to its object
Use the functionToString()
Convert the address to a string representation
Print Result
START Step 1-> declare class convert for conversion public class convert call class public static void Main() set IPAddress add = new IPAddress(new byte[] { 171, 32, 101, 11 } call Console.WriteLine(add.ToString()) End End STOP
using System; using System.Net; public class convert { public static void Main() { IPAddress add = new IPAddress(new byte[] { 171, 32, 101, 11 }); Console.WriteLine(add.ToString()); } }
Output Result
171.32.101.11