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. The Lounge
  3. Math with string, but why?

Math with string, but why?

Scheduled Pinned Locked Moved The Lounge
questionregexlounge
30 Posts 12 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.
  • P PIEBALDconsult

    You haven't met .net yet, have you? :sigh:

    J Offline
    J Offline
    jschell
    wrote on last edited by
    #21

    PIEBALDconsult wrote:

    You haven't met .net yet, have you?

    Meaning? Just to be clear...converting a string to a numeric, multiplying by 10 and then converting back to a string is going to be slower than appending to a string. In all of the languages that I know, including .Net.

    P 1 Reply Last reply
    0
    • J jschell

      harold aptroot wrote:

      Yes.. but the idea was not to use strings in the first place.

      Ah...but of course that wasn't the scenario presented. And not presumable in these days of prevelant GUIs and xml.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #22

      The scenario is intended to be the same one as in the earlier paragraphs of my post: math with strings for no good reason.

      J 1 Reply Last reply
      0
      • L Lost User

        The scenario is intended to be the same one as in the earlier paragraphs of my post: math with strings for no good reason.

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #23

        harold aptroot wrote:

        The scenario is intended to be the same one...

        ok.

        1 Reply Last reply
        0
        • J jschell

          PIEBALDconsult wrote:

          You haven't met .net yet, have you?

          Meaning? Just to be clear...converting a string to a numeric, multiplying by 10 and then converting back to a string is going to be slower than appending to a string. In all of the languages that I know, including .Net.

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #24

          Yes, but the appendification might not be as quick as just the multiplying by ten.

          J 1 Reply Last reply
          0
          • L Lost User

            No offense, but I wouldn't say "too lazy to port properly" is a valid excuse to keep that kind of code around.. But it's not as bad as doing it out of lack of understanding - at least there was some actual reason.

            J Offline
            J Offline
            Jeremy David Thomson
            wrote on last edited by
            #25

            There's a lot of code in the DEA algorithm to set bits from seemingly random bits in a source 64 bit block. Thinking about it the string binary might actually be more efficient that bitwise binary. Setting Bit 53 to the value of bit 17 in string binary is a simple byte to byte copy. In Bitwise operations its simple enough to specify in C by what might the assembly code look like? It would have to load the word containing the source bit. Do a TST if the bit is set or not. Branch to separate setting or unsetting logic. Load the destination word. OR the destination bit if setting, AND the compliment of the bit if unsetting. That has got to end up being more intructions than a simple byte to byte transfer. I think that was the whole point of the DEA algorithm, it was to computationally inefficient and time consuming.

            L 1 Reply Last reply
            0
            • J Jeremy David Thomson

              There's a lot of code in the DEA algorithm to set bits from seemingly random bits in a source 64 bit block. Thinking about it the string binary might actually be more efficient that bitwise binary. Setting Bit 53 to the value of bit 17 in string binary is a simple byte to byte copy. In Bitwise operations its simple enough to specify in C by what might the assembly code look like? It would have to load the word containing the source bit. Do a TST if the bit is set or not. Branch to separate setting or unsetting logic. Load the destination word. OR the destination bit if setting, AND the compliment of the bit if unsetting. That has got to end up being more intructions than a simple byte to byte transfer. I think that was the whole point of the DEA algorithm, it was to computationally inefficient and time consuming.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #26

              Now that's a more valid reason. You wouldn't do it with a branch of course, but yes it still kind of sucks. This is how I might write it:

              ; rcx = destination, rdx = source, for no reason
              btr rcx,53
              and edx,0x00020000
              shl rdx,36
              or rcx,rdx

              So 3 cycles, not so bad. Still, using strings would be faster for this step.

              1 Reply Last reply
              0
              • OriginalGriffO OriginalGriff

                I know what you mean, it does seem that some educators need a swift kick up the bottom. But then, they don't seem to teach the basics of computing any more - it's as if the computer is an irrelevant part of computing! Start 'em with assembler - that'll learn 'em! The one which annoys me most is SQL queries built by string concatenation rather than teaching the little buggers about parametrized queries from day one. Stupid, dangerous, and time-wasting when they try to add binary data to the table...

                Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                M Offline
                M Offline
                Mark H2
                wrote on last edited by
                #27

                Assembler schembler. Machine code is the way.

                OriginalGriffO 1 Reply Last reply
                0
                • M Mark H2

                  Assembler schembler. Machine code is the way.

                  OriginalGriffO Offline
                  OriginalGriffO Offline
                  OriginalGriff
                  wrote on last edited by
                  #28

                  Nah - machine code is for people who can cope with front panel switches, and My PC doesn't have those. :-D I could probably still key in the bootstrap loader for a Data General Nova in my sleep - I did that enough times over the years!

                  Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

                  "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                  "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Yes, but the appendification might not be as quick as just the multiplying by ten.

                    J Offline
                    J Offline
                    jschell
                    wrote on last edited by
                    #29

                    PIEBALDconsult wrote:

                    Yes, but the appendification might not be as quick as just the multiplying by ten.

                    I am hoping that you mean that if you start with a numeric, rather than starting with a string. That however isn't what I was comparing it to. If so then I would expect that all languages that the numeric multiplication (starting with a numeric) is faster. By quite a bit.

                    P 1 Reply Last reply
                    0
                    • J jschell

                      PIEBALDconsult wrote:

                      Yes, but the appendification might not be as quick as just the multiplying by ten.

                      I am hoping that you mean that if you start with a numeric, rather than starting with a string. That however isn't what I was comparing it to. If so then I would expect that all languages that the numeric multiplication (starting with a numeric) is faster. By quite a bit.

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #30

                      jschell wrote:

                      I am hoping that you mean that if you start with a numeric, rather than starting with a string.

                      Yes.

                      jschell wrote:

                      If so then I would expect that all languages that the numeric multiplication (starting with a numeric) is faster. By quite a bit.

                      Me too. I was casting aspersions on .net.

                      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