SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding zeros in front of a number

    Alright dudes,

    I'm in over my head, but I think I'm going to get through this one alive.

    I need to pull out the value of a vBulletin profile from a form field with multiple checkboxes. They've decide to output this as a binary number which can be decoded.

    I've got the the number.

    Let's assume it is this: 0101
    This tells me that that option0 and option2 have been selected.

    The problem I'm having is in the fact that binary goes "backwards". In other words, where I come from, the first item is on theft side. However, in my example binary # (0101) the 1 on the right side represents the first selection option.

    My plan was to bust this thing up with an explode and then "decode" the array.

    The problem is a I have 11 possible options in my form field. So 0101 is not really exact. 00000000101 would be exact (and what I think I need to achieve this).

    So, I need to be able to add the zeros in front of the binary # so that I can loop through them with some kind of reference as to what the first digit means.

    Of course, now that I think about it, I could explode each digit into an array and then flip the keys of the array. Hmmmm. I'll do this.

    Is there a better way?

    Brandon
    Home Recording Forum -
    Make 60% Commission Pushing my new mega system
    Killer Home Recording

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,426
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    str_pad() might be what you're looking for.

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2006
    Posts
    466
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Awsome! That's what I've been looking for.

    Thanks dude,
    Brandon Drury
    Home Recording Forum -
    Make 60% Commission Pushing my new mega system
    Killer Home Recording

  4. #4
    SitePoint Addict CVPer's Avatar
    Join Date
    Sep 2007
    Location
    Vancouver, BC, Canada
    Posts
    233
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you may use bitwise operations to get the values.
    * @location Vancouver, BC, Canada
    * @name Steve
    * @job PHP/MySQL, Drupal, WordPress Developer


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •