|
-
Jun 15th, 2009, 11:49 AM
#1
Thread Starter
Frenzied Member
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?
-
Jun 15th, 2009, 12:24 PM
#2
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
-
Jun 15th, 2009, 12:32 PM
#3
Thread Starter
Frenzied Member
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.
-
Jun 15th, 2009, 01:24 PM
#4
Addicted Member
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
-
Jun 15th, 2009, 01:24 PM
#5
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."
-
Jun 15th, 2009, 03:03 PM
#6
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
 
-
Jun 15th, 2009, 07:42 PM
#7
Addicted Member
Re: 7 into 1
 Originally Posted by shaggy hiker
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|