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

Problem With The Size Of Characters

hi there
i've got a problem with the characters in c.
i have declared a variable as a char so it must obviously have
size of a byte, but when i print the variable as an hex, the variable gets printed as something like ( ffffffda ), i can't dig it how this happens anyway.
this is a part of my code that i think is responsible for this confusion.

Expand|Select|Wrap|Line Numbers
  1. char leftrotate(char input)
  2. {
  3.     char result;
  4.     int b;
  5.     printf("before :%x\n",input);
  6.  
  7.         b = input & 0x80 ;
  8.     input<<=1;
  9.     if (b)
  10.     { 
  11.  
  12.         input |= 1;
  13.     }
  14.     printf("after :%x\n",input);    
  15.     //result = 0x000000FF & input;
  16.     return input;
  17.  
  18. }
Dec 28 '13 #1

✓ answered by weaknessforcats

The %x format of printf is an unsigned int. Your char is converted to an unsigned int and then displayed.

If you want to show only the two hex digits in your char, then don't use printf. Write your own function to do this.

4 1238
please answer, i'm in such a hurry.
Dec 28 '13 #2
weaknessforcats
9,208 Expert Mod 8TB
The %x format of printf is an unsigned int. Your char is converted to an unsigned int and then displayed.

If you want to show only the two hex digits in your char, then don't use printf. Write your own function to do this.
Dec 28 '13 #3
donbock
2,426 Expert 2GB
According to online documentation, the latest versions of C/C++ support the "hh" size qualifier to inform printf that the argument is a char (eg, "%hhx"). I've never used this feature so I don't know what will happen if you try it.
Jan 3 '14 #4
weaknessforcats
9,208 Expert Mod 8TB
Well give it shot and let us know what happened.
Jan 3 '14 #5

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

Similar topics

2
by: Sarah Michael | last post by:
Hi, I am running the following code to set a cookie but it is not working, please help me sorting out the problem. The code is from an online article http://www.devarticles.com/art/1/639 I...
1
by: Matthias Stern | last post by:
Hello! I've got a Javascript-PHP encoding problem. (1) Here is the short version: ============================== I'm sending a form textfield via Javascript(!) as URL parameter (GET)...
0
by: Stuart Newton | last post by:
We have just migrated a pile of ASP-driven content-managed websites from Win2000/SQL7 to Win2003/SQL2000 and noticed that, on some of them, certain characters such as the pound sign (£), 66..99...
1
by: Walt | last post by:
We are using ASP.net to develop a new website. The old website uses legacy ASP connecting to an Oracle database (9.2, W2k3, charecter set WE8ISO8859P1). The new site connects to the same database...
19
by: snowdy | last post by:
I am using Interactive C with my handboard (68HC11) development system but I've got a problem that I am asking for help with. I am not new to C but learning all the time and I just cant see how to...
7
by: Johannes | last post by:
Is it correct that Unicode characters with code points above 0x10FFFF are not supported by C#? I have a hard time believing this since it would eliminate some Asian languages. If it is true, is...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
1
by: Joe | last post by:
Can someone look at this code and tell me why I can not read in the input characters. //Invoice.hpp file #include <iostream> #include <string.h> using namespace std;
7
by: henrytcy | last post by:
Hi, How can I convert integer, for example 12113, to char array but without specify an array size in C programming? Thanks!
3
by: webEater | last post by:
Hey, I am writing a file that reads in an external file in the web and prints it out including the response header of the http protocol. I do this to enable cross domain XMLHttpRequests. I...
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: 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
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
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
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.