C语言ip地址转换成十六进制,将IP地址转换为十六进制
有时你会看到它的格式是这样的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
还没有评论,来说两句吧...