Shop OBEX P1 Docs P2 Docs Learn Events
Shifting strings — Parallax Forums

Shifting strings

ziplockziplock Posts: 9
edited 2009-09-24 06:52 in Propeller 1
I'm working a little bit 'o code, and I'm stumped.
I want to take a number (like this: 52034) and shift (multiply, divide, square root, add, subtract) one of the bits by a certain amount (i.e., take 52034, and add 2 to the 0)
How would I do this?

Any help would be appreciated!

-Adam

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hey! I'm Adam.
But YOU can call me ziplock.

Blog: braindrink.wordpress.com
"The only problem with the gene pool is that there is no lifeguard." -David Gerrold

Post Edited (ziplock) : 9/23/2009 1:29:08 AM GMT

Comments

  • he1957he1957 Posts: 58
    edited 2009-09-23 07:06
    Ziplock,

    Not sure what you mean. Is the 52034 actually a number; held in a variable as in x := 52034? If yes, then to get the zero to a 2, add 200. Other than that can you provide more information on what you are trying to do?

    Perhaps if you look at the number as 10,000's, 1000's, 100's, 10's and (decimal) digits that might help but it's not clear what you want to do.
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-09-23 14:38
    Hello ziplock,

    welcome to the propeller community !

    Please write us what you want to do in the end.
    It's a common phenomen that you have a detail-problem in mind and just ask for the detail.

    From my experience here I can tell you in 99% of all cases when somebody tells what he wants
    to do in the end. A lot of more, sometimes complete different and then more elegant solutions
    can be found.

    It needs much less time to read 10-20 sentences of a project-description than thinking about
    does he mean in this way ? or that way ? .... hm guessing if he means X then a solution might be....
    but if he means Y the solution will be ....

    So feel free to write a project-description

    best regards

    Stefan
  • kwinnkwinn Posts: 8,697
    edited 2009-09-23 14:46
    ziploc, how this is done depends to a great extent on how the data is stored. It could be as an ascii string, 4 bit BCD, fixed point binary number. or a floating point number. It sounds like it might be floating point, but we need to be sure.

    In other words we need more information to be of help.
  • ziplockziplock Posts: 9
    edited 2009-09-23 22:42
    Thanks for the welcome, Stefan!

    I'm trying to create random-random numbers, as the beginning of a radio encryption system.
    I'm generating two random numbers, using one to shift the other randomly, and then storing the result in ram.

    he1957, I'm using RealRandom to generate a two numbers; one between 0.0001 and 9.9999 and one between 0 and 5. Then, I use FloatString to convert the one between 0.0001 and 9.9999 to an integer.
    Kwinn, I'm storing the number in a long type variable. (long randVal)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Hey! I'm Adam.
    But YOU can call me ziplock.

    Blog: braindrink.wordpress.com
    "The only problem with the gene pool is that there is no lifeguard." -David Gerrold
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-09-24 05:51
    Hello ziplock,

    in the attached archive is a demo how to manipulate characters in strings

    best regards

    Stefan
  • kwinnkwinn Posts: 8,697
    edited 2009-09-24 06:40
    OK, a long is basically an unsigned 32 bit integer. I am assuming 52034 is a decimal number so to add a 2 to the "0" or hundreds digit would require adding a long integer value of 200 (decimal), converting 52034 to a bcd value and adding integer "2" to the hundreds digit, or converting it to ascii and adding integer "2" to the hundreds digit.
  • kwinnkwinn Posts: 8,697
    edited 2009-09-24 06:52
    The simplest would be to add a long with a value of 200 decimal to the long with the value 52034 decimal, but again it depends to some extent on the shift and add you want. Will you shift bits or decimal digits.
Sign In or Register to comment.