473,657 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bitwise Operations on double, float

I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.

May 17 '07 #1
4 6216
<si******@gmail .comwrote:
>I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Note that your first and second paragraph do not agree, the second on talks
only of doubles. There is an IEEE spec on doubles (and, I think, float)
which is reputedly used quite a bit. If you consider that as "portable" you
could restrict yourself to that and maybe get away with calling it portable.

I can't for the life of me imagine why anyone would want to do this. But I
refuse to ask you, it is none of my business and has no bearing on the
answer to the question.
May 17 '07 #2
On May 17, 5:53 pm, "osmium" <r124c4u...@com cast.netwrote:
<siryu...@gmail .comwrote:
I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.
Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Note that your first and second paragraph do not agree, the second on talks
only of doubles. There is an IEEE spec on doubles (and, I think, float)
which is reputedly used quite a bit. If you consider that as "portable" you
could restrict yourself to that and maybe get away with calling it portable.
I can't for the life of me imagine why anyone would want to do this. ButI
refuse to ask you, it is none of my business and has no bearing on the
answer to the question.
Well, it does, sort of. Because until we know what the
semantics of the operations are supposed to be, it's hard to say
how to best achieve them. What should the result of 1.33 |
3.1419 be? I can't think of anything reasonable.

--
James Kanze (Gabi Software) email: ja*********@gma il.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
May 17 '07 #3
On 17 Maj, 17:34, siryu...@gmail. com wrote:
I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.
No. Even if you can assume e.g. a IEEE float/double, using bit-magic
will not be portable as the representation might differ (similarly to
how unsigned ints have different endianness on different compters).

/Peter

May 18 '07 #4
On May 17, 4:34 pm, siryu...@gmail. com wrote:
I am trying to apply bitwise operations on float, double, and long
double values. I do not believe this is possible natively, so I
created a wrapper class to construct a double value given two
integers, similar to the bit representation of floating point numbers.
However, this is tedious and the decoding/encoding process is not
efficient.

Is there a portable way to apply AND, OR, XOR, >>, and << to doubles?
Thanks in advance.
I am not sure about the meaning of ANDm OR and XOR for doubles, but <<
can be interpreted as multiplication by 2.0 , similarly >2 can be
interpreted as multiplication by 0.5. This was the opertations are
consistent with the operatrion for integers.

May 18 '07 #5

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

Similar topics

11
9009
by: Randell D. | last post by:
Why would one use bitwise operators? I can program in various languages in some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise operators before, but never understood why anyone would use them - any real world examples or ideas? Examples follow (that I am reading in my Core JavaScript Guide 1.5). 15 & 9 yields 9 (1111 & 1001 = 1001) 15 | 9 yields 15 (1111 | 1001 = 1111) 15 ^ 9 yields 6 (1111 ^ 1001 = 0110) in...
8
6931
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the Keys.V element, regardless of any other keys. I know it will be a bitwise comparison, but I can't work out the correct syntax to use.
9
7024
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...
6
8405
by: jawilson2 | last post by:
Hello, I have some data that stores two 16-bit integers in a 32-bit float, and I would like to extract the data. I want to do something like //----------------------------------------------------------------- float *data; short *buff; int dataLen; //number of points in data //other code...
4
2074
by: skorobogatov | last post by:
I can't understand a little thing in bitwise operations. In PHP and Javascript 4653896912>>13 = -212992 In Python and Ruby 4653896912>>13 = 568102 In Python and Ruby - it's ok. I understand.
4
2126
by: alex | last post by:
hi friends ... i am facing a problem while detecting floating point operations in my project, please help me. i want to find out the places in my C/C++ project where i am doing floating point operations. As it is a big project it is not possible to check every line manually, so is there any other method to detect floating point operations in my project?
45
5276
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can multiple it by 1000 to get 11111 and the preform bitwise like <<2 to get 88888 and then divide by 1000 to go back to float 8.8888. but these seem like "nasty" way to do it. So maybe some of you have great tips? Thank you in advance! L R
29
5939
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 often done in Python because of keyword arguments and dicts, which are lot more versatile. Another major use, talking to hardware, is not something oft done in Python either. It seems like this occasional usage wouldn't justify having built-in...
0
8395
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
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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
8605
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...
0
7330
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.