Questions tagged [unsigned-char]

321 questions
4
votes
2 answers

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…
Steve
  • 115
  • 1
  • 3
  • 6
4
votes
5 answers

Since characters from -128 to -1 are same as from +128 to +255, then what is the point of using unsigned char?

#include #include int main() { char a=-128; while(a<=-1) { printf("%c\n",a); a++; } getch(); return 0; } The output of the above code is same as the output of the code below #include…
4
votes
2 answers

Convert basic_string to basic_string and vice versa

From the following Can I turn unsigned char into char and vice versa? it appears that converting a basic_string to a basic_string (i.e. std::string) is a valid operation. But I can't figure out how to do it. For example what…
Chris Redford
  • 16,982
  • 21
  • 89
  • 109
4
votes
1 answer

uint8_t operations, when do they overflow?

I'm not sure when I have to worry about overflows when using unsigned chars. This case is clear: uint8_t a = 3; uint8_t b = 6; uint8_t c = a - b; // c is 253 However, what happens here: float d = a - b; // d is -3 Are both a and be converted to…
Jan Rüegg
  • 9,587
  • 8
  • 63
  • 105
4
votes
3 answers

Convert QString into unsigned char array

I have a very basic question here. I tried googling for a while, because there are a lot of similar questions but none of the solutions worked for me. here is a code snippet that shows the problem: QString test = "hello"; unsigned char* test1 =…
samoncode
  • 466
  • 2
  • 7
  • 23
4
votes
3 answers

Comparison signed and unsigned char

It seems so strange. I found misunderstanding. I use gcc with char as signed char. I always thought that in comparison expressions(and other expressions) signed value converts to unsigned if necessary. int a = -4; unsigned int b = a; std::cout << (b…
Bikineev
  • 1,685
  • 15
  • 20
4
votes
2 answers

Strange issues regarding unsigned char * in C

So I have a method that returns an unsigned char * unsigned char* someMethod(num) unsigned short num; { //do some stuff with num and change values of a unsigned char * a = (unsigned char*) malloc(4); printf("a0 is %x\n",a[0]); …
Dao Lam
  • 2,837
  • 11
  • 38
  • 44
3
votes
2 answers

C++ Creating GUID from unsigned char array

I have a function that takes as input an array of unsigned char (16 values exactly) and creates a GUID (from GUID struct) by parsing all values to hexadecimal and passing a guid-formatted string to UuidFromStringA(). My code is as follows: GUID…
Uri Shapira
  • 369
  • 1
  • 2
  • 17
3
votes
2 answers

ostream operator overloading for unsigned char in C++

Given: typedef struct { char val[SOME_FIXED_SIZE]; } AString; typedef struct { unsigned char val[SOME_FIXED_SIZE]; } BString; I want to add ostream operator << available for AString and BString. std::ostream & operator<<(std::ostream &out, const…
pepero
  • 7,095
  • 7
  • 41
  • 72
3
votes
1 answer

How to convert elements in const unsigned char array to char

I am trying to iterate over a single const unsigned char array and assign/convert each element to a new char array using typecasting, every thread I've read suggests using typecasting however it's not working for me, here's my attempt: #include…
coder_xlf
  • 33
  • 3
3
votes
1 answer

How to convert unsigned char to binary representation

I'm trying to convert unsigned chars to their hex ASCII values but in binary form. For example: unsigned char C to 0100 0011 (43) I can get from hex to binary the issue is getting from char to its hex value. for (n = 0; n < 8; n++){ binary[n] =…
Hannah
  • 25
  • 1
  • 3
3
votes
1 answer

Why scanf overrides previously readed unsigned char variables with 0?

I tried to read several unsigned char values through scanf and found some strange bug. During the second call of scanf, first unsigned char variable gets overridden with 0. But writing scanf(" %hhu", &second); will cause override of the second…
Mr. White
  • 51
  • 5
3
votes
4 answers

Is there a possible memory leak for the codes below?

unsigned char *bin_data; unsigned char *bin_model; bin_data = new unsigned char[200]; memset(bin_data, 0, 200); bin_model = new unsigned char[200]; memset(bin_model, 0, 200); I was reviewing the code above and I have a gut…
Wolf
  • 91
  • 1
  • 7
3
votes
1 answer

What can I do with an unsigned char* when I needed a string?

Suppose that I have a unsigned char*, let's call it: some_data unsigned char* some_data; And some_data has url-like data in it. for example: "aasdASDASsdfasdfasdf&Foo=cow&asdfasasdfadsfdsafasd" I have a function that can grab the value of 'foo'…
jCuga
  • 1,523
  • 3
  • 16
  • 28
3
votes
1 answer

How to get an unsigned byte array from a BigInteger in Java?

I need to convert a BigInteger to an unsigned integer encoded in big-endian format but I am having issues since BigInteger.toByteArray returns a signed representation. How can I convert this value to an unsigned format? (Relatively) Helpful…
Hmmmmm
  • 778
  • 9
  • 20