Apr 27, 2005 #1 adityai Programmer Joined Aug 8, 2004 Messages 10 Location 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
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
Apr 28, 2005 1 #2 Bong Programmer Joined Dec 22, 1999 Messages 2,063 Location US 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 Upvote 0 Downvote
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
Apr 28, 2005 Thread starter #3 adityai Programmer Joined Aug 8, 2004 Messages 10 Location US My mistake. I wanted the mask to be 255.127.255.255 You are correct. Thank you. Upvote 0 Downvote