unsigned-char

How to increase/decrease an Unsigned Char?

I am trying to modify pixel values (8 bits per channel RGBA) by numerically increasing/decreasing the values by a certain amount. How can I do this in Objective-C or C? The following code generates a "Error: EXC_BAD_ACCESS" everytime. // Try to Increase RED by 50 for(int i = 0; i < myLength; i += 4) { //NSLog prints the values...

How to sprintf an unsigned char?

This doesn't work: unsigned char foo; foo = 0x123; sprintf("the unsigned value is:%c",foo); I get this error: cannot convert parameter 2 from 'unsigned char' to 'char' ...

Pointer type conversion: effect on buffer length?

Char is 1 byte unsigned short is 2 bytes So if I cast a char * to unsigned short *, will it change the length of the buffer? For example I am passing char * and length to a VUMeter function. The function casts the char * to unsigned short *: short* pln = (short*) buffer;` Now I loop through the buffer, so can I use same length which...

OpenAL causing leaks in my iPhone game. Help appreciated

Hi, I am integrating OpenAL in my iPhone game from code I found in this post, but the compiler gave me an error on this line of code: unsigned char *outData = malloc(fileSize);, so I changed it to this: unsigned char *outData = (unsigned char*) malloc(fileSize);. This got rid of the compiler errors, but seems to have thrown up two lea...

Connecting std::basic_ofstream<unsigned char> to a FIFO. bad_cast exceptions

Using gcc 4.4.3 on Linux 2.6.32, I get bad_cast exceptions when connecting std::basic_ofstream to a FIFO. Stepping though the debugger, I can see that the error is generated at various places in the standard library because the _M_codecvt member of the stream or filebuf object is NULL. Exactly where it happens depends on the order of op...

Maximum value of unsigned char

#include <stdio.h> int main() { unsigned char i=0x80; printf("%d",i<<1); return 0; } Why does this program print 256? As I understand this, since 0x80= 0b10000000, and unsigned char has 8 bits, the '1' should overflow after left shift and the output should be 0, not 256. ...

Problem converting C/C++ unsigned char to JAVA

The problem with unsigned char. I am reading a PPM image file which has data in ASCII/Extended ASCII. For a character, eg. '†' , In JAVA, after reading it as char and typecasting into int its value is 8224. In C/C++, after reading it as a unsigned char and typecasting into int its value is 160. How would i read in JAVA so as to ge...

Why is this comparison always true?

I have the following code in my file: unsigned char * pData = new unsigned char... ... if(pData[0] >= 160 && pData[0] <= 255) When I compile it, I get a warning from the compiler (gcc): Warning: comparison is always true due to limited range of data type How can this be? Isn't the range of an unsigned char 0-255? I'm confused....

C++ Converting a float to an unsigned char?

I'm new to C++, and doing a bit of googling I thought sprintf would do the job, but I get an error upon compiling that I can't convert between an unsigned char and a char. I need an unsigned char because I am going to print to an image file (0-255 RGB). unsigned char*** pixels = new unsigned char**[SIZE]; vector<float> pixelColors; .....

Is the signedness of char an interface issue?

Suppose I have a function void foo(char *) which, internally, needs to treat its input as a block of NUL-terminated bytes (say, it's a hash function on strings). I could cast the argument to unsigned char* in the function. I could also change the declaration to void foo(unsigned char *) Now, given that char, signed char and unsigne...