Binary to 32 bit numbers

Hi all,

I’m working on a problem on Codewars where an IPv4 address is converted
to
binary and then to a 32 bit number, but I don’t know how this happens.

Example
IP: 128.32.10.1
Converted to binary: 10000000.00100000.00001010.00000001
Converted to 32 bit: 2149583361

Now I’m with it on the binary conversion because I know how binary
works.
128 is written as 10000000 in binary, so this makes sense to me so far.

However I’m not sure how 32 bit numbers are constructed, so I have no
idea
how the above binary is then represented as the 32 bit number
2149583361.

Could someone explain how 32 bit numbers are calculated? Thanks!

Adam

Start from the rightmost number and multiply by 2^0 (1). Take the next
digit to the left and multiply by 2^1 (2). Continue like this until you
get through the entire 32 digits. Add them together as you go and this
will be your 32-bit number.


Brandon

www.BlindAdventures.com: Read about my adventures as a blind person

Latest Blog Post: Road Trip

Facebook: Brandon.Olivares
Twitter: @devbanana

It is essentially this: 1 + (10 << 8) + (32 << 16) + (128 << 24) =
2149583361

Mistral

if you include each group as a Hex number you get 80.20.0A.01 Also don’t
forget that IP numbers are unsigned. This number is the one you convert
and you will get 2149581057. The mistake you made was using base 10 to
convert the number not base 16

Windows 7 has a program called converter which will allow various
conversions of numbers of base 2, 8, 10, and 16 with different byte
sizes, char, short, long, and double long.