473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help combinging 3 numbers into 1 with bitwise operatioons

I have 3 5-digit numbers that i'd like to combine into one 15 digit number,
and later rip back into the original 3 5-digit numbers.

I know i can do this easily with some string manipulations, but i'm pretty
sure i can do the same thing with some bitwise operation like bit shifting or
something.

basically, if i have the following 3 numbesr

12321
34543
67876

i'd like to end up with

123213454367876

any ideas?
Feb 4 '06 #1
2 1290
Hi John,
bit shifting is modifying the bits in binary so you are talking about
base2, if you want to preserve the numbers after you combine them ie 12345 is
in base10 then you want to multiply to the power of 10 to shift the whole
number left. You also need to make sure that you have a datatype that is
capable of representing this large number. What you want to do is:
12321
34543
67876

i'd like to end up with

123213454367876
then it is:

123210000000000 + 3454300000 + 67876 = 123213454367876

which you could do by:

int i1 = 12321;
int i2 = 34543;
int i3 = 67876;

double dall = i1 * 1E10 + i2 * 1E5 + i3;

Hope that helps
Mark Dawson
http://www.markdawson.org


"john conwell" wrote:
I have 3 5-digit numbers that i'd like to combine into one 15 digit number,
and later rip back into the original 3 5-digit numbers.

I know i can do this easily with some string manipulations, but i'm pretty
sure i can do the same thing with some bitwise operation like bit shifting or
something.

basically, if i have the following 3 numbesr

12321
34543
67876

i'd like to end up with

123213454367876

any ideas?

Feb 4 '06 #2
john conwell wrote:
I have 3 5-digit numbers that i'd like to combine into one 15 digit number,
and later rip back into the original 3 5-digit numbers.

I know i can do this easily with some string manipulations, but i'm pretty
sure i can do the same thing with some bitwise operation like bit shifting or
something.

basically, if i have the following 3 numbesr

12321
34543
67876

i'd like to end up with

123213454367876

any ideas?


how about:?

long a = 12321;
long b = 34543;
long c = 67876;

long d = a*10000000000 + b*100000 + c;

hth,
Max
Feb 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
31
by: mark | last post by:
Hello- i am trying to make the function addbitwise more efficient. the code below takes an array of binary numbers (of size 5) and performs bitwise addition. it looks ugly and it is not elegant...
2
by: Zeb Davis | last post by:
Hello Newsgroup I'm new in C#, and I was wanting to create a console application involving generating 100 random numbers between 0 and 1000. After running that method, I want to write a method...
45
by: bobalong | last post by:
Hi I'm have some problem understanding how JS numbers are represented internally. Take this code for an example of weirdness: var biggest = Number.MAX_VALUE; var smaller = Number.MAX_VALUE...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any sort of example application of them. Call me what...
2
by: sudha30 | last post by:
hi please find code to add two numbers only by using bitwise operators
2
by: mahi543 | last post by:
can we write a program in java using bitwise operators to add two numbers
10
by: Rob Wilkerson | last post by:
I'm attempting to do some work around existing code that uses bitwise operations to manage flags passed into a function and I'm quite frankly unequipped to do so. I've never done much with bitwise...
11
by: Jordan | last post by:
I am trying to rewrite some C source code for a poker hand evaluator in Python. Putting aside all of the comments such as just using the C code, or using SWIG, etc. I have been having problems...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.