473,387 Members | 1,693 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.

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 6196
<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...@comcast.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*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
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
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...
8
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...
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...
6
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 ...
4
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...
4
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...
45
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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...

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.