Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to perform bit masking for an IP address 1

Status
Not open for further replies.

adityai

Programmer
Aug 8, 2004
10
US
Hello,

How can I do bit masking for an IP address.

Example:
224.210.1.1 mask with 255.239.255.255

Answer should be: 224.82.1.1
 
Are you sure about the second byte? I thought masking was a bitwise AND operation:
Code:
% set l1 [split 224.210.1.1 .]
224 210 1 1
% set mask [split 255.239.255.255 .]
255 239 255 255
% foreach a $l1 b $mask {lappend l2 [expr {$a&$b}]}
% set c [join $l2 .]
224.194.1.1
%
but that gives 194 for the second byte.


_________________
Bob Rashkin
rrashkin@csc.com
 
My mistake. I wanted the mask to be 255.127.255.255

You are correct.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top