Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Encoding IP addresses

Encoding IP addresses

Scheduled Pinned Locked Moved The Weird and The Wonderful
sysadmin
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bernhard Hiller
    wrote on last edited by
    #1

    Some years ago, I worked at the German office of a big international hospital information system manufacturer. The server was written in MUMPS (that's really a disease...), and lots of the code were developed at the US head quarters. Some day, we had problems in the communication between computers. Eventually we found out that our American colleagues stored IP addresses in two floating point numbers and then concatenated them with a ".", something like address=float1+"."+float2 It worked fine in the US, but in Germany we use a decimal comma instead of a decimal point, and "192,168.109,47" is not a correctly formed IP address...

    A S 2 Replies Last reply
    0
    • B Bernhard Hiller

      Some years ago, I worked at the German office of a big international hospital information system manufacturer. The server was written in MUMPS (that's really a disease...), and lots of the code were developed at the US head quarters. Some day, we had problems in the communication between computers. Eventually we found out that our American colleagues stored IP addresses in two floating point numbers and then concatenated them with a ".", something like address=float1+"."+float2 It worked fine in the US, but in Germany we use a decimal comma instead of a decimal point, and "192,168.109,47" is not a correctly formed IP address...

      A Offline
      A Offline
      adgonz
      wrote on last edited by
      #2

      Easy to fix. You can use the code we use at our company to convert floats between european/american decimals notation:

      Function CAMBIADECIMAL(ByVal NUMERO As String, ByVal TIPO As Integer) As String
          Dim I As Integer
          Dim J As Integer
      
          Dim ss As String
          Dim ss1 As String
          Dim PARTE1 As String
          Dim PARTE2 As String
      
          Select Case TIPO
              Case 1
                  ss = NUMERO
                  I = ss.IndexOf(".")
      
                  If I > 0 Then
                      J = ss.Length - I - 1
                      PARTE1 = ss.Substring(0, I)
                      PARTE2 = ss.Substring(I + 1, J)
                      ss1 = PARTE1 + "," + PARTE2
                      Return (ss1)
                  End If
                  Return ss
              Case 2
                  ss = NUMERO
                  I = ss.IndexOf(",")
      
                  If I > 0 Then
                      J = ss.Length - I - 1
                      PARTE1 = ss.Substring(0, I)
                      PARTE2 = ss.Substring(I + 1, J)
                      ss1 = PARTE1 + "." + PARTE2
                      Return (ss1)
                  End If
                  Return ss
          End Select
      End Function
      
      R 1 Reply Last reply
      0
      • A adgonz

        Easy to fix. You can use the code we use at our company to convert floats between european/american decimals notation:

        Function CAMBIADECIMAL(ByVal NUMERO As String, ByVal TIPO As Integer) As String
            Dim I As Integer
            Dim J As Integer
        
            Dim ss As String
            Dim ss1 As String
            Dim PARTE1 As String
            Dim PARTE2 As String
        
            Select Case TIPO
                Case 1
                    ss = NUMERO
                    I = ss.IndexOf(".")
        
                    If I > 0 Then
                        J = ss.Length - I - 1
                        PARTE1 = ss.Substring(0, I)
                        PARTE2 = ss.Substring(I + 1, J)
                        ss1 = PARTE1 + "," + PARTE2
                        Return (ss1)
                    End If
                    Return ss
                Case 2
                    ss = NUMERO
                    I = ss.IndexOf(",")
        
                    If I > 0 Then
                        J = ss.Length - I - 1
                        PARTE1 = ss.Substring(0, I)
                        PARTE2 = ss.Substring(I + 1, J)
                        ss1 = PARTE1 + "." + PARTE2
                        Return (ss1)
                    End If
                    Return ss
            End Select
        End Function
        
        R Offline
        R Offline
        reflex codeproject
        wrote on last edited by
        #3

        Here in Argentina we also use comma as floating point separator, and the correct code that always works is: a) to retrieve the current decimal separator: System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator b) to output ANY float using "." as its decimal separator [a float].ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat); c) to parse using an invariant culture, with "." as decimal separator. System.Convert.ToSingle("3.1415926", System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

        A 1 Reply Last reply
        0
        • R reflex codeproject

          Here in Argentina we also use comma as floating point separator, and the correct code that always works is: a) to retrieve the current decimal separator: System.Globalization.CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator b) to output ANY float using "." as its decimal separator [a float].ToString(System.Globalization.CultureInfo.InvariantCulture.NumberFormat); c) to parse using an invariant culture, with "." as decimal separator. System.Convert.ToSingle("3.1415926", System.Globalization.CultureInfo.InvariantCulture.NumberFormat);

          A Offline
          A Offline
          adgonz
          wrote on last edited by
          #4

          Hey, take it easy! I was just posting another horror ;P

          1 Reply Last reply
          0
          • B Bernhard Hiller

            Some years ago, I worked at the German office of a big international hospital information system manufacturer. The server was written in MUMPS (that's really a disease...), and lots of the code were developed at the US head quarters. Some day, we had problems in the communication between computers. Eventually we found out that our American colleagues stored IP addresses in two floating point numbers and then concatenated them with a ".", something like address=float1+"."+float2 It worked fine in the US, but in Germany we use a decimal comma instead of a decimal point, and "192,168.109,47" is not a correctly formed IP address...

            S Offline
            S Offline
            supercat9
            wrote on last edited by
            #5

            Is there any requirement that any particular octet of an IP address always be non-zero? I would think that if e.g. using a subnet mask of 255.255.254.0, an IP address of 192.168.1.0 or 192.168.0.3 would be perfectly valid.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups