Questions tagged [unsigned-char]

321 questions
6
votes
1 answer

Converting from C++ string to unsigned char* and back

What would be the code to convert an std::string to unsigned char* and back? str = "1234567891234567" unsigned char* unsignedStr = ConvertStrToUnsignedCharPointer(str); str1 = ConvertUnsignedCharToStr(unsignedStr); str and str1 must be same with no…
Sahil
  • 359
  • 2
  • 5
  • 13
6
votes
1 answer

Casting from `int` to `unsigned char`

I am running the following C++ code on Coliru: #include #include int main() { int num1 = 208; unsigned char uc_num1 = (unsigned char) num1; std::cout << "test1: " << uc_num1 << "\n"; int num2 = 255; …
user4063326
  • 85
  • 1
  • 2
  • 7
6
votes
1 answer

How do I #define an unsigned char* string?

I have following define in my code #define PRODUCTNAME "SomeName" and I want to send it with a function com_reply(unsigned char* msg, uint16_t lenght). Now I get a warning that my argument differs in signedness. I know what the problem is and…
Dehalion
  • 757
  • 1
  • 7
  • 16
6
votes
1 answer

How to read in binary data and cast to unsigned char (C++)

I have a raw image file that is saved in binary data (no encoding). I want to read in the file and cast the values to an unsigned char. But I'm not sure how to begin going about doing this. Each file contains 640x480 bytes. Each pixel is 8bits. I've…
c0d3rz
  • 649
  • 3
  • 15
  • 23
5
votes
4 answers

Difference between unsigned char and char pointers

I'm a bit confused with differences between unsigned char (which is also BYTE in WinAPI) and char pointers. Currently I'm working with some ATL-based legacy code and I see a lot of expressions like the following: CAtlArray
Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
5
votes
1 answer

Unexpected behaviour on underflow of unsigned char

The following program: #include #include int main () { unsigned char result1 {0}; unsigned char result2 {0}; result1 = (result1 - 1) % 8; result2 = result2 - 1; result2 = result2 % 8; std::cout <<…
JosF
  • 53
  • 4
5
votes
3 answers

Initializing an unsigned char array with hex values in C++

I would like to initialize an unsigned char array with 16 hex values. However, I don't seem to know how to properly initialize/access those values. When I try to access them as I might want to intuitively, I'm getting no value at all. This is my…
hatgirl
  • 101
  • 1
  • 1
  • 7
5
votes
3 answers

Casting from unsigned into signed char in C

I am converting an input raw pcm stream into mp3 using lame. The encoding function within that library returns mp3 encoded samples in an array of type unsigned char. This mp3-encoded stream now needs to be placed within an flv container which uses a…
Sriram
  • 10,298
  • 21
  • 83
  • 136
5
votes
5 answers

Generating random unsigned char values in C++

I was wondering how to generate random unsigned char values. My idea; rand()%255; since unsigned chars support between 0-255. I was wondering if this method could be improved(or is it the most legit way to do this)
Ali
  • 5,338
  • 12
  • 55
  • 78
4
votes
1 answer

Wrap python list to unsigned char*

Edit : Hi all !! I'm currently trying to access to C++ functions from Python and I'm facing to a problem when I try to pass Python list as argument to a function. here is the C++ function definition I'm trying to access (used to send command to…
Gojir4
  • 313
  • 2
  • 17
4
votes
3 answers

How to initialize unsigned char pointer

I want to initialize an unsigned char * buffer of length 1500 so that I can store values in it from some other sources.
Amit
  • 33,847
  • 91
  • 226
  • 299
4
votes
3 answers

Signed and unsigned char

Why are two char like signed char and unsigned char with the same value not equal? char a = 0xfb; unsigned char b = 0xfb; bool f; f = (a == b); cout << f; In the above code, the value of f is 0. Why it's so when both a and b have the same value?
T.g
  • 169
  • 2
  • 11
4
votes
4 answers

for (unsigned char i = 0; i<=0xff; i++) produces infinite loop

Why does the following c code end up in an infinite loop? for(unsigned char i = 0; i <= 0xff; i++){} It is the same result with: for(unsigned char i = 0; i <= 0xff; ++i){} In which way do I have to modify the code, to get it working as expected…
fragwürdig
  • 219
  • 2
  • 6
4
votes
2 answers

Convert unsigned char array into uint8_t array?

I need convert unsigned char array into unit8_t array maybe someone has an idea how to do it? I tried to look for information on the Internet, but unfortunately I did not succeed. :)
4
votes
5 answers

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…
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
1 2
3
21 22