473,795 Members | 2,968 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

All Arithmatic operations using Bitwise operators only

32 New Member
Is it possible to perform all arithmetic operations (+,-,*,/) using Bitwise operations only. Please consider signed numbers also.
Thank You.
Dec 25 '08
14 19134
JosAH
11,448 Recognized Expert MVP
@Banfa
You still must have eggnog in your brains ;-) A left shift is a logical shift to the left; a right shift shifts in the sign bit (by definition) if an artithmetic shift is used with a signed int, otherwise a zero bit is shifted in (a logical shift). But you're right: an unsigned shift has always been more 'natural' to me as well ;-)

kind regards,

Jos
Dec 28 '08 #11
Aftabpasha
32 New Member
Thank you all for your replies. So, from these posts, I think, one can say that there can be different methods for performing the basic arithmetic operations using bit-wise operators on different machines, and therefore it is necessary to know how certain basic bit-wise operations are performed on different platforms before using them in coding. Otherwise it is better to use normal arithmetic operators (+,-,*,/), specially when you want platform-independent code.
Thank you all once again.
Kind Regards.
Dec 30 '08 #12
donbock
2,426 Recognized Expert Top Contributor
It is _always_ better to use normal arithmetic operators to perform arithmetic functions. The exceptions to this simple rule are so exceptional that you're unlikely to ever run into them.
@Aftabpasha
Dec 30 '08 #13
Bassem
344 Contributor
Thanks a lot Banfa,
I ment to return x not y.

As you said the platform who provides the operations, we just use.

Josah, your idea is clear using Half-Adder or Full-Adder, and that leads me to ask why Bytes.com have no community for Microprocessors / Microcontroller s ?

It may be replaced to suggestions (Dept.) - if it's correct to say- Thanks anyway,
I get widely help from your (all of you) answers for many questions other put.

Regards for all,
Bassem
Dec 30 '08 #14
Aftabpasha
32 New Member
Thank you all. Donbock, I'll remember your advice.

Regards,
Aftab
Dec 31 '08 #15

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

Similar topics

4
3104
by: Jason | last post by:
I am going through the Geek Challenges on the Open Source Institute Website: http://www.osix.net/modules/geek/ The instructions for Level 4 are: "This challenge requires you to use some of your favourite mathematical operators, and also get to do simple simple file IO. Additionally you will learn bit operations. # download this file. Process every byte, if it is greater than 30
4
2490
by: Mike Hodkin | last post by:
As a beginning student of C++, books reference "bitwise operators" and give brief examples, but I have not read a good explanation of what they are used for. One reference mentioned that they are used in hardware programming. Are they used very often in routine C/C++ programming, and what for? thanks, MJH
14
2361
by: Tony Johansson | last post by:
Hello Experts! Assume I have a class called SphereClass as the base class and a class called BallClass that is derived from the SphereClass. The copy constructor initialize the left hand object in this case object b2 below. It also initialize subobject from class SphereClass. The BallClass copy constructor looks like this. BallClass::BallClass(const BallClass& bc) : SphereClass(bc)
9
7030
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 from 0 to 15 and I need to compare it to 15 in order to find if it contains the values 1, 2, 4, or 8. To represent it more graphically, the value 1010 when ANDed with 1000 or 0010 will produce either true or a value greater than 0. I believe...
10
2178
by: Emilio | last post by:
Do I use 'or' for bitwise operations where in c# I use | ?
4
1885
by: AMDRIT | last post by:
Gang, I always get confused when it comes to 1's and 0's. I would like to perform a bitwise operation on a value based on checked boxes. Am I doing this right? assuming TurmsRemote.Weekdays has values of
5
5803
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 you will but I cannot seem to see the purpose for bitwise operators. Especially the operators bitwise OR ( | ) and bitwise AND ( & ), I'm just not getting it. I have searched around and really haven't found anything that gave explanation to why...
16
3254
by: Shawnk | last post by:
I would like to perform various boolean operations on bitmapped (FlagsAttribute) enum types for a state machine design as in; ------------------- enum portState { Unknown, Open,
8
8793
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. BRgds, Daniel.
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10165
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.