473,434 Members | 1,818 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,434 software developers and data experts.

How to reverse a Unsigned Char??

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

Oct 24 '06 #1
4 6752

ra*******@gmail.com wrote:
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.
Go to Google Groups and search for "reverse" in comp.lang.c

Oct 24 '06 #2
ra*******@gmail.com wrote:
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
There's no operator or standard function for this in C, but if you
google for 'reverse bits in a byte' you will find e.g.

http://graphics.stanford.edu/~seande...ReverseObvious

and lots of other results.
Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\__________________________ http://toerring.de
Oct 24 '06 #3
2006-10-24 <11**********************@e3g2000cwe.googlegroups. com>,
ra*******@gmail.com wrote:
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
static unsigned char CSStab4[256]=

{
0x00,0x80,0x40,0xc0,0x20,0xa0,0x60,0xe0,
0x10,0x90,0x50,0xd0,0x30,0xb0,0x70,0xf0,
....
And so on in much the same manner.

x = 0x8a;
x[CSStab4] == 0x51;
Oct 24 '06 #4
ra*******@gmail.com wrote:
>
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
unsigned char bit_rev(unsigned char byte)
{
unsigned hi_mask = ((unsigned char)-1 >1) + 1;
unsigned lo_mask = 1;

do {
if (!(byte & hi_mask) != !(byte & lo_mask)) {
byte ^= hi_mask | lo_mask;
}
hi_mask >>= 1;
lo_mask <<= 1;
} while (hi_mask lo_mask);
return byte;
}

--
pete
Oct 24 '06 #5

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

Similar topics

47
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...
6
by: John Deuf | last post by:
Does somebody has a better algorithm than mine to reverse a byte (i.e. bit 0 becomes 7, bit 1 becomes 6 ...) unsigned char u=0, c = TESTVALUE; int i; for (i=0 ; i<4 ; i++) u |= ((c & (1 << ...
20
by: sahukar praveen | last post by:
Hello, I have a question. I try to print a ascii file in reverse order( bottom-top). Here is the logic. 1. Go to the botton of the file fseek(). move one character back to avoid the EOF. 2....
10
by: Tomás | last post by:
Looking at the following function: #include <cstddef> #include <iostream> template<typename T, std::size_t len> void PrintOutStrings( const char* const (&Array) ) { for (std::size_t i = 0;...
47
by: sudharsan | last post by:
could any one please give me a code to reverse a string of more than 1MB .??? Thanks in advance
20
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)
11
by: lovecreatesbea... | last post by:
/*reverse a string, e.g. from "abc" to "cba". no library function invoking is allowed.*/ void reverse(char *s){ char *p = s; char c; int n1 = 0, n2 = 0; while (*p++) n2++;
40
by: KG | last post by:
Could any one tell me how to reverse the bits in an interger?
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
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...
1
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.