473,503 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to swap the nibbles whit dev++?

2 New Member
Hello, i've got a project and im missing one of the parts "yes i've just started whit programming"
I'm using Dev++

How to swap the nibbles.

Expand|Select|Wrap|Line Numbers
  1. Ect   1010 - 1101
  2.    To 1101 - 1010
  3. "
  4.  
  5. #define _swapNibble(x) ((x<<4)|(x>>4))
  6.  
  7. int main()
  8. {
  9.     // On executing you will get
  10.     // x before swap = 0x1c
  11.     // x after swap = 0xc1
  12.     char x = 0x1c;
  13.     printf("x before swap = %x\n",x);
  14.  
  15.     _swapNibble(x);
  16.     printf("x afer swap = %x",x);
  17. }
""
This is what i've got but got some faults"

Thank you.
Oct 16 '13 #1
4 1703
Rogerup
2 New Member
Change the #define to:

#define _swapNibble(x) (((x<<4)|(x>>4))&0xFF)

or

#define _swapNibble(x) ((char)((x<<4)|(x>>4)))
Oct 16 '13 #2
deeyay
2 New Member
In function `int main()':



\c++\Calc\tip\SAH\you.cpp:10: error: `printf' undeclared (first use this function)


: error: (Each undeclared identifier is reported only once for each function it appears in.)

Execution terminated

. i can't see what i've done wrong..
Oct 16 '13 #3
Rogerup
2 New Member
At the beginning of your code put:

#include <stdio.h>
Oct 16 '13 #4
donbock
2,426 Recognized Expert Top Contributor
Line 12: you declare x as a char. This type should only be used for characters. If you want a small integral type then use either signed char or unsigned char, depending on whether or not you want the value to be signed. (However, in subsequent comments I argue for using type int.)

Line 5: your macro is named _swapNibble. The C Standard reserves all names with a leading underscore just in case they are needed in future versions of the Standard. You should not use a reserved name. I suggest you remove the leading underscore.

Line 13: conversion specifier %x expects an int argument; however you pass x, which is a char. This is a good reason to declare x as an int.

Line 5: the expression that the macro expands to has type int despite the operand being type char. This is another good reason to declare x as an int.

Line 15: this statement evaluates an expression and then discards the result. You need an assignment statement if you want to assign the result to some variable.
Oct 17 '13 #5

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

Similar topics

6
9937
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...
4
3000
by: Sreejith K | last post by:
How to interchange the two nibbles of a byte without using any bitwise operator.
2
1971
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...
1
1596
by: Admir Hod?ic via AccessMonster.com | last post by:
I use some old fashion program whit DBF files and now i step by step moving thth to acces. Problem occurs when i try to link DBF tables whit MEMO FILED wich requvest file whit ''name''.ftp extension...
1
1961
by: news.wanadoo.nl | last post by:
Hi, I have found whit google this form in this group. But i'n not good in javascript :(. I try and error normal but i only error now :P Whit i now want to now how can i get access to the vars...
4
4087
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
6163
by: ma740988 | last post by:
Consider: # include <vector> # include <iostream> # include <cstdlib> # include <ctime> bool ispow2i ( double n ) {
1
6152
by: aaron | last post by:
Output of "top" prior to initiation of mysql: load averages: 0.60, 0.97, 1.05 19:03:45 44 processes: 43 sleeping, 1 on cpu CPU states: 97.1% idle, 0.0% user, 0.8% kernel, 2.1% iowait, ...
14
3243
by: Wouter | last post by:
Hi, I try to make the follow. I want that i can click on a text link and that then a link wil be copyed in a input form box (<input type="text" name="img_url" />). I have google-ed about how...
0
7199
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
7322
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
6982
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
5572
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,...
1
5000
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
3161
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...
0
1501
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 ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
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...

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.