Results 1 to 7 of 7

Thread: 7 into 1

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    7 into 1

    I'm looking for a way to take seven 2 digit numbers & combine them into one number to store in a database. The numbers represent hours for each day of the week & I only have one field to store them in. Then I need to be able to take the stored number & decode it back into the original seven numbers. Anyone have any clever ideas how I can do this?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: 7 into 1

    convert them to strings, concatenate them, with some sort of delimiter in the middle? To get them back, read the string, & split on the delimiter.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: 7 into 1

    I thought of that, but the field in the database where I need to save the number is integer type, so that rules out saving it as a string with delimiters.

  4. #4
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: 7 into 1

    Can you datatype handle an integer value as high as

    024,024,024,024,024,024,024?

    Each grouping is the value for that day.
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

  5. #5
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: 7 into 1

    Are you sure it is an integer and not a long in the database?

    But even so, if it's a maximum of 24 hours a day, then you could use a base 10 representation of a base 24 number (which would only be 7 digits long) which CAN be represented as an integer, I believe.
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: 7 into 1

    What JugglingReferee suggested would work as long as you are using a 64 bit integer. You can take each number as a single byte, then bit-shift each byte into one of the eight bytes in the Long Integer. You would be wasting tons of space in each byte, since you would only be using the low five bits. Alternatively, you could switch to non-military time, which would mean that you would have hours 1-12, which would fit into the low three bits of a byte. You could then use the fourth bit to indicate AM/PM. By doing that, you could pack all seven slots into four bytes, since each byte could hold two days.
    My usual boring signature: Nothing

  7. #7
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: 7 into 1

    Quote Originally Posted by shaggy hiker View Post
    what jugglingreferee suggested would work as long as you are using a 64 bit integer. You can take each number as a single byte, then bit-shift each byte into one of the eight bytes in the long integer. You would be wasting tons of space in each byte, since you would only be using the low five bits. alternatively, you could switch to non-military time, which would mean that you would have hours 1-12, which would fit into the low three bits of a byte. You could then use the fourth bit to indicate am/pm. By doing that, you could pack all seven slots into four bytes, since each byte could hold two days.
    +1 !!
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

Posting Permissions

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



Click Here to Expand Forum to Full Width