how can i convert the ip address into decimal
이전 댓글 표시
Hello,
for exemple i have this address and i want to convert it in decimal how can I do this with matlab
192.192.192.2
댓글 수: 3
dpb
2019년 8월 2일
What does "convert into decimal" mean to you? It is decimal as is...
Joel Handy
2019년 8월 2일
Do you mean how do I parse out the 4 fields into numeric data?
ipFields = str2double(split('192.192.192.2', '.'))
답변 (1개)
Joel Handy
2019년 8월 2일
편집: Joel Handy
2019년 8월 2일
ipFields = uint8(str2double(split('192.192.192.2', '.')))';
typecast(fliplr(ipFields), 'uint32')
% Explanation
dec2hex(192)
dec2hex(2)
Each field of an Ip address is an 8 bit (1 byte) integer, which can be represented by 2 digits in hexadecimal. If you squish the four 8 bit fields together, you get a single 32 bit integer which can be represented by 8 hexadecimal digits.
192.192.192.2 => [192 192 192 2] => [0C 0C 0C 02] => 0C0C0C02 => 3233857538
The typecast is where you "squish" the individual bytes together.
The field reordering is necessary due to the order of bits and bytes in memory. Different systems store bits in different orders. Some systems store data most significant bit, MSB, first while other store data least significant bit first, LSB. Some systems put the most significant byte before the least significant byte, which is called big endian, while others do the revers which is called little endian. You need to be aware of how your system stores data in order to correctly order the bytes before you squish them together.
댓글 수: 4
mez kari
2019년 8월 2일
Joel Handy
2019년 8월 2일
I'm a little rusty on calling C code from Matlab as well as my C++. I know you need to use loadlibrary before calling calllib. I believe the call would look something like this:
loadlibrary(<dll file path>, <header file path>);
result = calllib(<dll name>, 's_SetFeature', int32(input1), uint32(input2), uint32(input3));
There are a lot of unknowns. the function you call out, s_SetFeature, doesnt appear in the code snippet you shared. There is a function SetFeature but it only takes two inputs not three.
#DEFINES are macros. anywhere int he code where you See TRIG_INTERNAL, its getting replaced with (0 << 25) at compile time. In this case (0 << 25) appears to be a bitshift operator. But its bitshifting 0 which doesnt really make sense to me since an unsigned integer 0 is still 0 wether you bitshift it or not.
Hopefully someone else can chime in with a better answer to your follow up. If this answers your original question though, I encourage you to accept the answer to help anyone with a similar question.
mez kari
2019년 8월 5일
dpb
2019년 8월 5일
"how to write (0<<25) in matlab"
0 is still 0
>> bitshift(0,25)
ans =
0
>>
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!