Options

Converting from CIDR to Dotted Decimal

veritas_libertasveritas_libertas Member Posts: 5,746 ■■■■■■■■■■
I have finished up my ICND1 book and now understand clearly how to find resident subnet numbers if I get them in dotted decimal such as: 192.168.0.100. What I am now wondering is if there is a simple way to convert from CIDR (such as:170.0.0.1/15) to dotted decimal.

Comments

  • Options
    mohcommohcom Member Posts: 44 ■■□□□□□□□□
    Something like this? IP to CIDR online converter

    Edit... actually the above is IP to CIDR...
    - CCNP (Work In Progress)
    - CCNA
    - CCENT
    - Security+
    - B.S. Computer Science (Info. Systems Security)
  • Options
    Forsaken_GAForsaken_GA Member Posts: 4,024
    Honestly, there's only so many possibilities. I ended up memorizing them just from seeing them so often. Internally, I just take the CIDR mask, divide by 8 and the result is the number of octets at 255, and I do the conversion with the remainder, adding from the left with the number of bits left.

    Ie, if given a /27, 27 / 8 = 3 remainder 3, so I know 255.255.255. off the bat, 3 bits from the left is 128 + 64 + 32 or 224, so 255.255.255.224. But most days I just look at a /27 and I know the last octet of the mask is .224 because that's how it's associated in my head. /28 for 240, /29 for 248, /30 for 252.

    Of course these days alot of people **** and just use subnet calculators hehe
  • Options
    veritas_libertasveritas_libertas Member Posts: 5,746 ■■■■■■■■■■
    mohcom wrote: »
    Something like this? IP to CIDR online converter

    Edit... actually the above is IP to CIDR...

    Not really, I want to KNOW how to do it.
  • Options
    veritas_libertasveritas_libertas Member Posts: 5,746 ■■■■■■■■■■
    Of course these days alot of people **** and just use subnet calculators hehe

    Unfortunately that won't help with the test icon_wink.gif

    As I understand it you aren't allowed to bring a calculator right?
  • Options
    Forsaken_GAForsaken_GA Member Posts: 4,024
    Newp! That's where the scratch pad and pens come in handy. Though honestly, the only thing I've ever had to use them for was VOIP bandwidth calculations on other exams
  • Options
    veritas_libertasveritas_libertas Member Posts: 5,746 ■■■■■■■■■■
    Newp! That's where the scratch pad and pens come in handy. Though honestly, the only thing I've ever had to use them for was VOIP bandwidth calculations on other exams

    I believe that's: Newb icon_lol.gif

    I just want to make sure I can convert from CIDR to Dotted Decimal in a quick and efficient matter. If anyone else has advice I am all ears. Thanks Forsaken_GA!
  • Options
    Forsaken_GAForsaken_GA Member Posts: 4,024
    Honestly, you probably won't have to do enough of it that it'll effect your bottom line on the amount of time you have for the test. Don't get too hung up on it and lose focus of something else.

    The best advice I can probably give you in that regard is to simply memorize it (at least for the bits beyond a /24) and then write it down before you even start the exam. That way if you see it and need to convert it during the exam, just reference your scratch sheet. Converting a CIDR mask is a whole lot less of a pain in the ass than convering hex.
  • Options
    mikedisd2mikedisd2 Member Posts: 1,096 ■■■■■□□□□□
    I just want to make sure I can convert from CIDR to Dotted Decimal in a quick and efficient matter. If anyone else has advice I am all ears.

    Honestly, just memorise the numbers: 128, 192, 240, 248, etc. How's your mental arithmetic?icon_smile.gif

    It can be done many ways, just whatever works. I know 240 is followed by 248. The next increment must then be 4, so 252, etc.

    I also count with my fingers icon_razz.gif. From 255.255.255.0, /28 is the fourth finger and therefore the subnets are blocks of 16 (-2). Whatever works.

    I'm still going to write out a **** sheet before starting the exam. No point making it hard on myself.
  • Options
    elphrank0elphrank0 Member Posts: 67 ■■□□□□□□□□
    Veritas, Think that every question is a subnet question. The best way to do it is to memorize the information. If you do not have a copy of CCNA study guide by Todd Lammle, I would recommend it. His CH 3 goes into great detail and shows you how to subnet in your head. Then you take from his "What you know" section and make a chart and just memorize everything you need. Involves zero math. And it seems the easiest to me.

    It takes repetition to memorize. Also know how to count by your 16's.
  • Options
    gbadmangbadman Member Posts: 71 ■■□□□□□□□□
    mikedisd2 wrote: »
    Honestly, just memorise the numbers: 128, 192, 240, 248, etc. How's your mental arithmetic?icon_smile.gif

    It can be done many ways, just whatever works. I know 240 is followed by 248. The next increment must then be 4, so 252, etc.

    I also count with my fingers icon_razz.gif. From 255.255.255.0, /28 is the fourth finger and therefore the subnets are blocks of 16 (-2). Whatever works.

    I'm still going to write out a **** sheet before starting the exam. No point making it hard on myself.


    Counting fingers? I should toss you into the nearest bin just for being so primitive! icon_wink.gif
    But I agree with all that's been said. CIDR/VLSM is just binary maths at the end of the day. Most of the people who tremble at the thought of it only do so because they haven't done it enough.
    You can go back and forth with ease if you know the powers of 2 up to 256 (which would help a lot) and that 256 (or 2^icon_cool.gif and 32 (no. of bits in IPV4) are the magic numbers that a lot pivots around.

    For instance, you know that /27 is .224 because that's 5 bits used, and 2^5 is 32. Hence 256-32=224. Conversely to convert back to CIDR, you know that 224 is 256-32, and 32 is 2^5. Hence the mask is 32-5=/27
    If you don't know the powers of 2 then you can simply move downwards from 256 or move upwards from 2.

    The same principle also applies to knowing the address ranges in each mask. You know there are 30 usable addresses (32-2) in /27 from 5^2=32. And if you remember that you can't overlap when assigning ranges, you're pretty much set. :D

    This at least is how I do it. I'd be glad to get input from anyone who has an even simpler way of looking at things. Or more importantly, a way of doing the bits beyond /24 that's just as easy. Right now I usually resort to pen and paper beyond /24. icon_wink.gif
    [FONT=georgia, bookman old style, palatino linotype, book antiqua, palatino, trebuchet ms, helvetica, garamond, sans-serif, arial, verdana, avante garde, century gothic, comic sans ms, times, times new roman, serif]A pessimist is one who makes difficulties of his opportunities and an optimist is one who makes opportunities of his difficulties

    -[/FONT][FONT=georgia, bookman old style, palatino linotype, book antiqua, palatino, trebuchet ms, helvetica, garamond, sans-serif, arial, verdana, avante garde, century gothic, comic sans ms, times, times new roman, serif]Harry Truman[/FONT]
  • Options
    dstock7337dstock7337 Member Posts: 95 ■■■□□□□□□□
    Not really, I want to KNOW how to do it.
    Kudos! Yeah, anyone can use the calculator but actually knowing what it means and how to is the gold standard. With lots of practice, you'll get faster each time. Personally, I'm still a little slower than I'd like to be but it just takes practice.

    Now heres the real fun: flip between CDIR/VLSM and subnet wildcards in dotted decimal. Whew that is some FUN! :D
    "The only true wisdom is in knowing you know nothing." - Socrates
  • Options
    will824will824 Registered Users Posts: 1 ■□□□□□□□□□
    Greetings guy. I came to this forum researching an algorithm to do the conversion, without avail.

    Then I realized I had to do the algorithm myself and here it is in Javascript.

    Cheers!


    /**
    * Parses a Mask Decimal (IP way) into a CIDR (0-32)
    * @author william.cornejo
    */
    function parseMaskDecimalToCIDR(ipArray){

    var cidr = 0;

    for(var i = 0; i < ipArray.length ; i++){

    for(var j = 1 ; j <= 8 ; j++ ){
    var sectionValue = parseInt(ipArray);
    var sectionCalculation = 256 - Math.pow(2,(8-j));
    if( sectionValue == sectionCalculation){
    cidr = cidr + j;
    break;
    }
    }
    }

    return cidr;

    };

    /**
    * Parses a CIDR (0-32) into a Decimal (IP) representation
    * @author william.cornejo
    */
    function parseMaskCIDRToDecimal(cidr){

    var arrayIP = [];

    if(typeof(cidr) == 'undefined' || cidr == null || cidr == '' || cidr == 0){
    arrayIP = [0,0,0,0];
    }else{

    var divisionWhole = Math.floor((parseInt(cidr)-1)/icon_cool.gif;
    var cidrFraction = cidr - (8*divisionWhole);

    for(var i = 0; i<4 ; i++){

    if(divisionWhole == i){
    arrayIP = 256 - Math.pow(2,(8-cidrFraction));
    }else if(divisionWhole > i){
    arrayIP = 255;
    }else{
    arrayIP = 0;
    }
    }
    }

    return arrayIP;
    }



Sign In or Register to comment.