Bitwise Anding question

jlhctjlhct Member Posts: 92 ■■□□□□□□□□
Hello,

I'm starting my preparation for 70-291 and I've come across something in my Syngress book that I don't understand:

If i'm bitwise anding these 2 #'s: 146.64.160.9 and 255.255.224.0 why is the result = 146.64.160.0

Am I not understanding something along the way?

Thanks!

Comments

  • dynamikdynamik Banned Posts: 12,312 ■■■■■■■■■□
    What did you expect it to be?

    Write them both out in binary if you have trouble visualizing it. Both bits you're ANDing have to be a 1 in order to have the result be 1. Since the last octect is all 0s, all ANDed bits in that octect will be 0. Is that what you didn't understand?
  • jlhctjlhct Member Posts: 92 ■■□□□□□□□□
    dynamik wrote:
    What did you expect it to be?

    Write them both out in binary if you have trouble visualizing it. Both bits you're ANDing have to be a 1 in order to have the result be 1. Since the last octect is all 0s, all ANDed bits in that octect will be 0. Is that what you didn't understand?

    I was expecting the 1st octect to be 145 instead of 146, since the 1st one should look like this:

    10010001

    If I add those up, i'd get 145 right? I think thats what I'm not getting.

    thanks!
  • undomielundomiel Member Posts: 2,818
    Ok, break out the calculator.

    156.64.160.9 in binary:

    10010010.01000000.10100000.00001001

    255.255.224.0 in binary:

    11111111.11111111.11100000.00000000

    Then we'll do a bitwise AND on them.

    10010010.01000000.10100000.00001001
    AND
    11111111.11111111.11100000.00000000
    =
    10010010.01000000.10100000.00000000

    Which converts to you 146.62.160.0 number.

    Let's do another one.

    156.64.62.102
    255.255.224.0

    10010010.01000000.10100010.01100110
    AND
    11111111.11111111.11100000.00000000
    =
    10010010.01000000.10100000.00000000

    You end up with the same number 146.62.160.0 so that means that 146.62.162.102 is in the same subnet as 146.62.160.9.
    This is delving into subnetting. 146.62.xxx.xxx is normally a class B network. 255.255.0.0 mask. Using 255.255.224.0 borrows some of the bits from the hosts assignments to give additional subnets but not so many hosts per a subnet.

    I'm not a subnetting expert by any means so I'd recommend taking a look at royal's post and learntosubnet.com for a much better explanation. Or someone else will post a much better explanation. But that should give you a start.
    Jumping on the IT blogging band wagon -- http://www.jefferyland.com/
  • dynamikdynamik Banned Posts: 12,312 ■■■■■■■■■□
    jlhct wrote:
    I was expecting the 1st octect to be 145 instead of 146, since the 1st one should look like this:

    10010001

    If I add those up, i'd get 145 right? I think thats what I'm not getting.

    thanks!

    Well, that does add up to 145, but where did you get 145 from?

    Also, keep these shortcuts in mind:

    If one of the octets is 255, the value will be identical to the other octect. i.e. 255 AND 146 = 146
    If one of the octets is 0, the value will be 0. i.e. 9 AND 0 = 0

    The only octet you need to do any work on is the one that falls somewhere in the middle.
  • jlhctjlhct Member Posts: 92 ■■□□□□□□□□
    Ok, I think the book has it listed wrong.

    They have 10010001 for the first octet (146)where I think it should be like undomiel posted: 10010010

    This is why I'm only adding up to 145 instead of 146.

    All of the rest of the #'s in the example add up.

    I was starting to think I was too dense to pick this up LOL

    I'll definitely check out that subnetting post, thanks!
  • dynamikdynamik Banned Posts: 12,312 ■■■■■■■■■□
    You can register your book here to view the errata for it: http://www.syngress.com/solutions/

    You should always have a print-out of the errata handy, so you don't drive yourself crazy because of their errors.
  • jlhctjlhct Member Posts: 92 ■■□□□□□□□□
    dynamik wrote:
    You can register your book here to view the errata for it: http://www.syngress.com/solutions/

    You should always have a print-out of the errata handy, so you don't drive yourself crazy because of their errors.

    HAHAHA Thanks!!

    I lost my passoword so i'm waiting for that before I proceed. Thanks for that link!
Sign In or Register to comment.