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

How to swap the nibbles

46
Hi all,

In C, I don't know how to shift the nibble.... i.e suppose let us take 'char' data type has 1 byte(8 bits) so to shift the 4 bits to other side and vice versa...

Tell me how to do this


With Regards,
VELMURUGAN.H
Dec 22 '06 #1
2 21890
horace1
1,510 Expert 1GB
Hi all,

In C, I don't know how to shift the nibble.... i.e suppose let us take 'char' data type has 1 byte(8 bits) so to shift the 4 bits to other side and vice versa...

Tell me how to do this


With Regards,
VELMURUGAN.H
you could shift the top nibble 4 bits right and the lower nibble 4 bits left then OR them together, e.g.
Expand|Select|Wrap|Line Numbers
  1.     y = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
  2.  
Dec 22 '06 #2
shanoj
1
you could shift the top nibble 4 bits right and the lower nibble 4 bits left then OR them together, e.g.
Expand|Select|Wrap|Line Numbers
  1.     y = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
  2.  
thats really an expert answer!! I am just a starter in C was stuck in a similar situation..and was thinking of using IF loop's..bt then,i thought of looking up on the net and this seems to be too good.and the BEST way of doing it...Thank u..
Mar 10 '08 #3

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

Similar topics

6
by: Hugh Lutley | last post by:
I'm not much of a programmer so I need a bit of help on this one. I'm writing a Java prog that communticates over rs232 to tape machines and I've got a problem which I'm not sure how to solve. My...
5
by: Steve Hill | last post by:
Hi, suppose I have a vector allocated on the heap. Can I use a temporary (stack based vector) and swap to clear it, or is this unsafe. e.g. vector<int> *v; vector<int> tmp; v->swap(tmp); // is...
4
by: Sreejith K | last post by:
How to interchange the two nibbles of a byte without using any bitwise operator.
2
by: ma740988 | last post by:
So I'm reading the C++ coding standards(Shutter & Andrei), more specifically item 56. There's a statement: "Prefer to provide a nonmember swap function in the same namespace as your type when...
7
by: Kai-Uwe Bux | last post by:
Hi folks, I am still struggling with the rules for name lookup. Please consider: namespace xxx {
9
by: Jongmin Lee | last post by:
Hi Everybody, I have very simple code snippet to explain my problem. Class "Swap" is construncted in "Main" with two initial variables. Later, "Swap" class is going to swap those two...
4
by: Niels Dekker (no reply address) | last post by:
When calling swap as follows (as recommanded in Effective C++, 3rd Edition, by Scott Meyers), what swap is chosen to be called? using std::swap; swap(a, b); Suppose there is a global ::swap...
9
by: ma740988 | last post by:
Consider: # include <vector> # include <iostream> # include <cstdlib> # include <ctime> bool ispow2i ( double n ) {
28
by: Jess | last post by:
Hello, It is said that if I implement a "swap" member function, then it should never throw any exception. However, if I implement "swap" non- member function, then the restriction doesn't...
4
by: George2 | last post by:
Hello everyone, The following swap technique is used to make assignment operator exception safe (means even if there is exception, the current object instance's state is invariant). It used...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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...

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.