473,406 Members | 2,217 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,406 software developers and data experts.

Simple Bitwise C/C++ operator function

Hi,
I have two seperate unsigned longs and want to add one infront of the other.
baicaully something like:
unsigned long one;
unsigned long two;
unsigned long long add;

where say: one = 1001000011110010111011100101; //28 binary = 151989989
and two = 11111101000011100011111111100001;//32 binary = 4245569505
and I want
add = 10010000111100101110111001011111110100001110001111 1111100001
(add = |one|two| )

Is there a function for this? or can anyone help me do this? (There must be an easy way I just can't think of any because strtoul() only goes as high as unsigned longs and not unsigned long longs.)

Thanks.
Mar 2 '07 #1
3 1746
better to use them as characters unless u dont need them in any arithmatic operations.
define 2 arrays of type (char)
> then use a loop that reads characters (use the instruction: getchar)
> in each iteration, check if the it reads the symbol or not the end yet
> when u get the symbol, switch to the other variable with another array
> Merge arrays in one array
> get one char. from the first array and put it in a separate array
> when u reach the end of the array, move to the second array and add it to the new one
*> now u got 1 array with all 1s and 0s
************************************************** *****************************************
maybe there is another way without using 2 arrays at first
Mar 2 '07 #2
lqdeffx
39
I agree, can't think of any functions off hand that could merge numeric types. might be easier & safer though to convert to a C++ string, or at least it would be easier for me. one way to convert then just do a strcat() and its all good.
Mar 2 '07 #3
Thanks a lot guys.

I actaully did:
add = binOne;
add = add << 32;
add = add + binTwo;

and it worked great. I thought for some reason << 32 would just push the bits off the end but it adds 0's so it worked awesome.

ex: I thought
binOne = 1101
binOne << 3 would then = 1000 (getting rid of the 110)
but it really equals 1101000

Thanks!
Mar 2 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Michael B. Trausch | last post by:
I have a question regarding bitwise operators, I've been trying to figure this out for about two days now, and I just can't seem to get it. What I'm trying to do is use a variable to hold a bitmask...
12
by: Elaine Jackson | last post by:
Is there a function that takes a number with binary numeral a1...an to the number with binary numeral b1...bn, where each bi is 1 if ai is 0, and vice versa? (For example, the function's value at...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
9
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write the synax for it in C#. I have a value that ranges...
5
by: Bill Dee | last post by:
I need help converting a tiny piece of code which uses the bitwise complement operator from C# to VB.NET. In C# I currently have this: long useThis = Myclass.ALLCONSTANTS; long doNotUse =...
10
by: David R. | last post by:
I want to do bitwise operation on some large integers. For example, Response.Write CBool(2 AND 2^30) ' returns False Response.Write CBool(2 AND 2^31) ' CRASHED! Looks like the AND...
1
by: mweltin | last post by:
Dear list memebers: I have been searching google and various lists but have come up with little that helps me. Perhaps it is my lack of diction that limits my search results. Be that as it may,...
4
by: John Dann | last post by:
I'm trying to generate a 4-byte unsigned integer in VB2005 that encodes a number of bit-level variables. What I need to do is to be able to compute a value for the uint that is based on specific...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
8
by: Daniel Gutson | last post by:
Hi, I just wanted to share another library for doing type-safe bitwise operations in C++: http://bitwise-enum.googlecode.com I found it useful, so hopefully it'll be for somebody else as well....
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.