Could any one tell me how to reverse the bits in an interger?
Jun 20 '07
40 36498
<bo******@gmail .comschrieb im Newsbeitrag
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
On Jun 20, 11:56 am, "Joachim Schmitz" <nospam.j...@sc hmitz-
digital.dewrote :
int reverse_bits(in t n)
{
return ~n;
}
That's inverting (1 turn into 0 and vice versa), not reverting. I understood the OP wants the laest significant bit being the most significate, the 2nd least being the second most and so on.
I did not understand that: the OP asked for to "reverse the bits in an
interger". This function reverses all bits in the integer. What you
are proposing is reversing the order of the bits, which is different.
Apparently (looking at the other answers in this thread) only you and
Richard understood it that way.
My point is that inverting (see http://en.wikipedia.org/wiki/Inverse_%28logic%29) is not the same as
reverting.
Bye, Jojo
Joachim Schmitz said:
<bo******@gmail .comschrieb im Newsbeitrag
news:11******** **************@ k79g2000hse.goo glegroups.com.. .
>On Jun 20, 11:56 am, "Joachim Schmitz" <nospam.j...@sc hmitz- digital.dewrot e:
>int reverse_bits(in t n) { return ~n; }
That's inverting (1 turn into 0 and vice versa), not reverting. I understood the OP wants the laest significant bit being the most significate, the 2nd least being the second most and so on.
I did not understand that: the OP asked for to "reverse the bits in an interger". This function reverses all bits in the integer. What you are proposing is reversing the order of the bits, which is different.
Apparently (looking at the other answers in this thread) only you and
Richard understood it that way.
Nevertheless, it demonstrates that the specification was inadequate.
Over 28% of the respondents who had expressed an interpretation at the
time of writing have chosen to interpret "reverse the bits in an
integer" as "reverse the bits in an integer" rather than "reverse the
order of the bits in an integer".
My point is that inverting (see http://en.wikipedia.org/wiki/Inverse_%28logic%29) is not the same as
reverting.
And reverting is not the same as reversing. And reversing is not the
same as reversing the order.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www.
<bo******@gmail .comwrote:
On Jun 20, 11:56 am, "Joachim Schmitz" <nospam.j...@sc hmitz-
digital.dewrote :
int reverse_bits(in t n)
{
return ~n;
}
That's inverting (1 turn into 0 and vice versa), not reverting. I understood the OP wants the laest significant bit being the most significate, the 2nd least being the second most and so on.
I did not understand that: the OP asked for to "reverse the bits in an
interger". This function reverses all bits in the integer. What you
are proposing is reversing the order of the bits, which is different.
Most people whose natural language is English would say "invert the *sense*
of the bits", for what you are describing.
"Richard Heathfield" <rj*@see.sig.in validha scritto nel messaggio news:Wt******** *************** *******@bt.com. ..
Joachim Schmitz said:
><bo******@gmai l.comschrieb im Newsbeitrag news:11******* *************** @k79g2000hse.go oglegroups.com. ..
>>On Jun 20, 11:56 am, "Joachim Schmitz" <nospam.j...@sc hmitz- digital.dewro te: int reverse_bits(in t n) { return ~n; }
That's inverting (1 turn into 0 and vice versa), not reverting. I understood the OP wants the laest significant bit being the most significate, the 2nd least being the second most and so on.
I did not understand that: the OP asked for to "reverse the bits in an interger". This function reverses all bits in the integer. What you are proposing is reversing the order of the bits, which is different.
Apparently (looking at the other answers in this thread) only you and Richard understood it that way.
Nevertheless, it demonstrates that the specification was inadequate.
Over 28% of the respondents who had expressed an interpretation at the
time of writing have chosen to interpret "reverse the bits in an
integer" as "reverse the bits in an integer" rather than "reverse the
order of the bits in an integer".
>My point is that inverting (see http://en.wikipedia.org/wiki/Inverse_%28logic%29) is not the same as reverting.
And reverting is not the same as reversing. And reversing is not the
same as reversing the order.
http://dictionary.reference.com/browse/reverse
Yes, it is not 100% clear, but the most likely meaning is reversing
the order. (Anyway, since correct answers to both the meanings of
the question have been giving, arguing on which one was meant,
until the OP tells us, is sort-of waste of time.)
"Richard Heathfield" <rj*@see.sig.in validschrieb im Newsbeitrag
news:Wt******** *************** *******@bt.com. ..
Joachim Schmitz said:
><bo******@gmai l.comschrieb im Newsbeitrag news:11******* *************** @k79g2000hse.go oglegroups.com. ..
>>On Jun 20, 11:56 am, "Joachim Schmitz" <nospam.j...@sc hmitz- digital.dewro te: int reverse_bits(in t n) { return ~n; }
That's inverting (1 turn into 0 and vice versa), not reverting. I understood the OP wants the laest significant bit being the most significate, the 2nd least being the second most and so on.
I did not understand that: the OP asked for to "reverse the bits in an interger". This function reverses all bits in the integer. What you are proposing is reversing the order of the bits, which is different.
Apparently (looking at the other answers in this thread) only you and Richard understood it that way.
Nevertheless, it demonstrates that the specification was inadequate.
True, incomplete and leaves room for interpretation.
Over 28% of the respondents who had expressed an interpretation at the
time of writing have chosen to interpret "reverse the bits in an
integer" as "reverse the bits in an integer"
"invers the bits in an integer". (or "invert"?) A bit that is set when read
left to right is still set when read right to left, so revers wouldn't be
the right word. But hell, this isn't my native language...
rather than "reverse the order of the bits in an integer".
That could indeed have been the full specification.
Time for the OP to show up and confirm.
>My point is that inverting (see http://en.wikipedia.org/wiki/Inverse_%28logic%29) is not the same as reverting.
And reverting is not the same as reversing.
Oops, of course I meant reversing as the OP wrote.
And reversing is not the same as reversing the order.
What else? To me it is the same. What would 'reverse a string' be to you?
Turn the characters upside down? 8-)
Bye, Jojo
Army1987 said:
>
"Richard Heathfield" <rj*@see.sig.in validha scritto nel messaggio
news:Wt******** *************** *******@bt.com. ..
>Joachim Schmitz said:
<snip>
>>My point is that inverting (see http://en.wikipedia.org/wiki/Inverse_%28logic%29) is not the same as reverting.
And reverting is not the same as reversing. And reversing is not the same as reversing the order.
http://dictionary.reference.com/browse/reverse
Yes, it is not 100% clear, but the most likely meaning is reversing
the order.
To your mind, maybe. But it makes much more sense to write the
specification in a way that makes the requirement clear, right from the
start, to *everybody*.
(Anyway, since correct answers to both the meanings of
the question have been giving, arguing on which one was meant,
until the OP tells us, is sort-of waste of time.)
I am not, and have not been, arguing about which one the OP meant. I am
arguing that a clear specification is a sine qua non of a correct
program.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www.
osmium wrote:
<bo******@gmail .comwrote:
>On Jun 20, 11:56 am, "Joachim Schmitz" <nospam.j...@sc hmitz- digital.dewrot e:
>int reverse_bits(in t n) { return ~n; }
That's inverting (1 turn into 0 and vice versa), not reverting. I understood the OP wants the laest significant bit being the most significate, the 2nd least being the second most and so on.
I did not understand that: the OP asked for to "reverse the bits in an interger". This function reverses all bits in the integer. What you are proposing is reversing the order of the bits, which is different.
Most people whose natural language is English would say "invert the *sense*
of the bits", for what you are describing.
I'm not most people [1], but I think you're wrong.
For those with any interest in the matter at all,
I think they'd say "invert the bits", with
no nonsense about "sense". Or they'd use "flip".
Or "reverse". Or "complement ".
I rather suspect that the OP meant "reverse
the order of the bits", but experience in
support on another mailing list suggests that
users asking about something different from
what they /say/ they're asking about
happens often enough that mere suspecting
doesn't bake the biscuit.
[1] For which we're all grateful.
--
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England
Joachim Schmitz said:
"Richard Heathfield" <rj*@see.sig.in validschrieb im Newsbeitrag
news:Wt******** *************** *******@bt.com. ..
<snip>
>And reversing is not the same as reversing the order.
What else? To me it is the same. What would 'reverse a string' be to
you? Turn the characters upside down? 8-)
It could reasonably be interpreted as ROT-((UCHAR_MAX + 1)/2).
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk
email: rjh at the above domain, - www.
Anonymous wrote:
On Jun 20, 2:40 pm, KG <Kriti.Goyal.t. ..@gmail.comwro te:
>Could any one tell me how to reverse the bits in an interger?
First of all you need to know the size of integer, then you should
go somthing like this:
Well, in all this nonsense I have seen nothing that actually
reverses the order of bits in an unsigned int, independent of
sizeof int. So try this:
while (i) {
push(i & 1, stack);
i >>= 1;
}
while (notempty(stack )) {
i <<= 1;
j = pop(stack);
i != j;
}
with suitable declarations, stack, etc.
--
<http://www.cs.auckland .ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfoc us.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
On Wed, 20 Jun 2007 10:55:40 -0400, CBFalconer <cb********@yah oo.com>
wrote:
>Anonymous wrote:
>On Jun 20, 2:40 pm, KG <Kriti.Goyal.t. ..@gmail.comwro te:
>>Could any one tell me how to reverse the bits in an interger?
First of all you need to know the size of integer, then you should go somthing like this:
Well, in all this nonsense I have seen nothing that actually reverses the order of bits in an unsigned int, independent of sizeof int. So try this:
while (i) {
push(i & 1, stack);
i >>= 1;
}
while (notempty(stack )) {
i <<= 1;
j = pop(stack);
i != j;
}
with suitable declarations, stack, etc.
You have just exposed a second and much more serious ambiguity, to wit,
what precisely is meant by integer and how is it delimited. The issue is
what determines the number of leading zeroes and the length of the answer.
To illustrate suppose that our "integer" is 00110001 (8 bit words). Is the
correct answer 10001100 or 100011 or 00100011? This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kapil Khosla |
last post by:
Hi,
I am trying to reverse a byte eg.
11010000 should look like
00001011
Plz note, it is not a homework problem and I do not need the c code
for it.
Just give me an idea how should I proceed about it.
I know basic bit manipulation , shifting left, right and have done
|
by: Laszlo Szijarto |
last post by:
In C#, wha't the best way to reveser the bit order of a data type and then
convert it back to that datatype?
So, take a byte, reverse bits, convert it back to a byte. I tried to get a
BitArray and then call Array.Reverse(), but how to convert back to byte?
How about flipping an odd number of bits, say a group of 4 bits, then
converting the 4 bits back to an int equivalent?
Thanks you in advance for your help,
|
by: aatish19 |
last post by:
1: Write a program that asks the user to input an integer value and
print it in a reverse order
Sample Output
Enter any number 65564
Reverse of 65564 is 46556
2: Write a program that takes a string as an input and print it in
reverse order.(don't use bulit-in/library function).
Sample Output
Enter any string: i m Kashif
|
by: mike7411 |
last post by:
Is there any easy way to reverse the order of the bits in a byte in
C++?
(i.e. 00000001 becomes 10000000)
|
by: ranjanmg1 |
last post by:
I have a unsigned char.. i need to reverse it.. what the easiest way to
do it?? i dont want to tap each bit save and restore etc etc....
Is it possible to perform some bitwise operation which will give the
reversed char.
e.g., unsigned char x = 0x8A
am expecting an output after reversal x = 0x51
| |
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...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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,...
|
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...
|
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();...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |