C语言ip地址转换成十六进制,将IP地址转换为十六进制

矫情吗;* 2022-10-14 15:57 302阅读 0赞

有时你会看到它的格式是这样的HEX IP地址。

0xC0.0xA8.0x2A.0x48

这里是我如何做到这一点在我的头上,因为我不擅长与大的数字,因为十六进制是基于16下图是DEC左和HEX的权利。

0 = 0

1 = 1

2 = 2

3 = 3

4 = 4

5 = 5

6 = 6

7 = 7

8 = 8

9 = 9

10 = A

11 = B

12 = C

13 = D

14 = E

15 = F

然后,一旦你有图表记忆,这只是基本的数学

192 = C0 = (192/16) = 12.0 = take the remainder (0 x 16) = 0 convert it to Hex (0)

then take the result (12) divide it by 16 (12/16) and if it’s less then 1 then just

covert the remainder to hex 12 = C then add it up backwards for C0

168 = A8 = (168/16) = 10.8 = he remainder (.8 x 16) = 12.8 convert it to hex (A) then

take the result (12) divide it by 16 (12/16) and if it’s less then 1 then just covert

the remainder to hex 0 = 0 then add it up backwards for 0A8 or A8

42 = 2A = (42/16) = 2.625 = The remainder (.625 x 16) = 10 convert it to hex (A) then

take the result (2) divide it by 16 (2/16) and if it’s less then 1 then just covert the

remainder to hex 2 = 2 then add it up backwards for 2A

72 = 48 = Your turn

发表评论

表情:
评论列表 (有 0 条评论,302人围观)

还没有评论,来说两句吧...

相关阅读

    相关 IP地址转换函数

    人们习惯用可读性好的字符串来表示IP地址,比如用点分十进制字符串表示IPv4地址,十六进制表示IPv6地址。 下面3个函数用于点分十进制字符串表示的IPv4地址及用网络字节