Questions tagged [unsigned-char]

321 questions
-1
votes
1 answer

convert struct to unsigned char through overloaded operator << and >> (see update)

I have this struct with 2 attributes (one char and one int, for a memory usage of 3 bytes: struct Node { char data; int frequency; } I try overload the operators << and >> for this struct, for being able to read and write this struct from…
Kleber Mota
  • 8,521
  • 31
  • 94
  • 188
-1
votes
3 answers

Char addition does not have expected result in C

Can someone explain me how is this at the end a=?,b=?,c=-124 and not a=?,b=?,c=132 This is code: #include int main() { char a = 'D', b='C', c='A'; a = c + 'D'; b = a + b + 'A'; c = b - a; a = a - b + 'C'; b = b - 68; …
-1
votes
1 answer

Appending an unsigned char to a vector changes its value

I have the following 2D vector: vector> dates; I also have the following unsigned char array: unsigned char date[3] = {1, 18, 108}; When I push_back this array to dates it sets all the unsigned char elements to 204: date =…
brickbobed
  • 169
  • 1
  • 10
-1
votes
1 answer

Return unsigned char array to main function

Background: My original main() is: int main(int argc, char *argv[]) { unsigned char output[16] = {0x00}; // copied from code // .... (some steps to calculate output[i]) for (i = 0; i < 16; i++) { printf("%02X ",…
TJCLK
  • 183
  • 12
-1
votes
2 answers

Using a vector of unsigned chars in a map

I need help using unsigned chars in std::vectors that are inside of a std::map. This is how I declare the std::map: std::map> DataMap; The problem comes when I try to assign a std::vector to the std::map. it->first…
JackCross
  • 37
  • 5
-1
votes
1 answer

C function to read binary file doesn't work if used by other function.?

I wrote this function to return an unsigned char * containing the data from any file(using rbread mode) it looks like this: uchar * get_file_data (char *f_name, luint *len) { // verify file struct stat sBuffer; int iRc; iRc =…
Otard95
  • 3
  • 4
-1
votes
3 answers

Converting an int to an unsigned char in C

I've never needed to use unsigned char before, but I've recently became curious about their ability to store integers. Through a little bit of reading I have done I've found that the cast from int to unsigned char is done implicitly, but I have also…
Derek
  • 11
  • 4
-1
votes
2 answers

Is this Integer Promotion? How does it work?

I was just experimenting and I tried out two printf()s. unsigned char a = 1; a = ~a; printf("----> %x %x %x %x", ~a, a, ~a, ++a); This one gave the output ----> ffffff00 ff ffffff00 ff Next one was unsigned char a = 1; printf("----> %x %x %x %x",…
Tattu
  • 327
  • 1
  • 3
  • 15
-1
votes
2 answers

Converting an integer to an hexadecimal unsigned char array in C++

I need to convert an integer int parameter to an hexadecimal unsigned char buffer[n]. If integer is for example 10 then the hexadecimal unsigned char array should be 0x0A To do so I have the following code: int parameter; std::stringstream…
Cristina
  • 21
  • 1
  • 5
-1
votes
1 answer

Remove first bytes of a unsigned char*

I'm currently working on a project where I need to work with unsigned char* and unwanted bytes in there. I'll describe the situation: 1/ I have an iOS app that loads an image (UIImage). 2/ I transform this UIImage into a unsigned char* (thanks to…
Chris
  • 3
  • 2
-1
votes
1 answer

How to add a 8 bytes Hex enumeration value to an unsigned char pointer?

I have this Hexadecimal enumeration of 8 bytes: enum MyEnum { OPTION_1 = 0x000000; OPTION_2 = 0x000001; }; Is there any way to add OPTION_1to the following pointer (this pointer will contain other binary data): unsigned char*…
Farah
  • 2,469
  • 5
  • 31
  • 52
-1
votes
1 answer

Why "cout" works weird for "unsigned char"?

I have the following code: cvtColor (image, image, CV_BGRA2RGB); Vec3b bottomRGB; bottomRGB=image.at(821,1232); When I display bottomRGB[0], it displays a value greater than 255. What is the reason for this?
Khawar Ali
  • 3,462
  • 4
  • 27
  • 55
-1
votes
1 answer

Converting string to unsigned char

I've spent a while trying to get a string to turn into an array of unsigned chars, but no luck. I'm doing an AES implementation and I have everything set up except the input reading part. This is the code I have ATM. string text = "E3 FD 51 12" ; …
inzombiak
  • 171
  • 2
  • 14
-1
votes
2 answers

Add values to char in c?

Hey guys so I have a char and I want to add some integer/double to it. The char must be a signed char, so I can't just make it an int. char var = -55; printf("Char is %d, add, char is now: %d\n", var, var+2); That code works, but as soon as I want…
Travv92
  • 791
  • 4
  • 14
  • 27
-2
votes
1 answer

How to convert unsigned long long int into unsigned char*?

Say for instance I have this unsigned long long int: unsigned long long int test_int = 0xcfffedefcfffeded; // 14987959699154922989 How could I convert test_int into the following unsigned char* array: unsigned char test_char[] =…