Questions tagged [unsigned-char]
321 questions
11
votes
2 answers
Convert unsigned char[10] to QBytearray;
I've seen a lot o questions around this, but so far none worked for me.
I've tried the 2 most common answers but I get the same error.
being but an unsigned char buf[10];
this,
QByteArray databuf;
databuf = QByteArray::fromRawData(buf, 10);
or…

SamuelNLP
- 4,038
- 9
- 59
- 102
9
votes
3 answers
Is plain char usually/always unsigned on non-twos-complement systems?
Obviously the standard says nothing about this, but I'm interested more from a practical/historical standpoint: did systems with non-twos-complement arithmetic use a plain char type that's unsigned? Otherwise you have potentially all sorts of…

R.. GitHub STOP HELPING ICE
- 208,859
- 35
- 376
- 711
9
votes
5 answers
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…

Nathan Osman
- 71,149
- 71
- 256
- 361
9
votes
1 answer
-Wconversion warning while using operator <<= on unsigned char
When I compile the following code with gcc :
int main()
{
unsigned char c = 1;
c <<= 1; // WARNING ON THIS LINE
return 0;
}
I get this warning :
conversion to ‘unsigned char’ from ‘int’ may alter its value [-Wconversion]
Why ? What is…

Caduchon
- 4,574
- 4
- 26
- 67
9
votes
3 answers
C: char vs. unsigned char for non-ASCII text data
This question:
What is an unsigned char?
does a great job of discussing char vs. unsigned char vs. signed char in C.
However, it doesn't directly address what should be used for non-ASCII text. Thus if I have an array of bytes that represents text…

Craig S. Anderson
- 6,966
- 4
- 33
- 46
9
votes
2 answers
Convert QByteArray to std::vector
I tried to convert QByteArray to std::vector using this code:
unsigned char* buffer = (unsigned char*)byteArrayBuffer.constData();
std::vector::size_type size = strlen((const char*)buffer);
std::vector…

Jacob Krieg
- 2,834
- 15
- 68
- 140
8
votes
2 answers
Conveniently copy std::vector to input stream (std::istream) object
I'm trying to make use of a function which comes in a 3rd party lib and expects an input stream object in which binary file data is transported.
Signature looks like that:
doSomething(const std::string& ...,
const std::string& ...,
…

Rip-Off
- 358
- 1
- 4
- 14
8
votes
6 answers
Comparing unsigned char and EOF
when the following code is compiled it goes into an infinite loop:
int main()
{
unsigned char ch;
FILE *fp;
fp = fopen("abc","r");
if(fp==NULL)
{
printf("Unable to Open");
exit(1);
}
while((ch =…

Amol Sharma
- 1,521
- 7
- 20
- 40
8
votes
2 answers
Maximum value of unsigned char
#include
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…

Variance
- 873
- 2
- 10
- 10
8
votes
2 answers
Printing values of keypoint descriptor matrix opencv
I'm having some trouble printing the values of the descriptor matrix obtained through the use of the 'compute' method of any opencv descriptor extractor. I want to print the descriptor of a feature to a file one by one, but always when I access some…

Alberto A
- 1,160
- 4
- 17
- 35
7
votes
3 answers
Any compiler which takes 'char' as 'unsigned' ?
Is there any C compiler which takes the default type of char as unsigned unless explicitly mentioned by the user in the file or project settings?
/Kanu_

Renjith G
- 4,718
- 14
- 42
- 56
7
votes
2 answers
Type "char" in C++
Is there an easy way to convert between char and unsigned char if you don't know the default setting of the machine your code is running on?
(On most architectures, char is signed by default and thus has a range from -128 to +127. On some other…
user2928017
7
votes
3 answers
Comparing non null-terminated char arrays
I have a compressed unsigned char array of a known size. Due to compression considiration I don't store the null-terminator at the end. I want to compare it to another array of the same format. What
would be the best way to do so?
I thought…

David Tzoor
- 987
- 4
- 16
- 33
7
votes
2 answers
Scanf unsigned char in hex
I am trying to change data in array, this is part of my code:
u_char paket[100];
//here i put some data into array and then trying to change it by user
scanf("%hhx.%hhx.%hhx.%hhx.%hhx.%hhx", &paket[0], &paket[1], &paket[2], &paket[3], &paket[4],…

user2306381
- 71
- 1
- 3
7
votes
6 answers
Invalid conversion from ‘void*’ to ‘unsigned char*’
I have the following code;
void* buffer = operator new(100);
unsigned char* etherhead = buffer;
I'm getting the following error for that line when trying to compile;
error: invalid conversion from ‘void*’ to ‘unsigned char*’
Why do I get that…

jwbensley
- 10,534
- 19
- 75
- 93