Questions tagged [unsigned]

An unsigned variable is a variable that can only represent non-negative numbers.

An unsigned variable is a variable that can only represent non-negative numbers, as opposed to a signed variable which can represent both positive and negative numbers.

1251 questions
6
votes
2 answers

How to determine if 8bit WAV File is signed or unsigned, using Java and without javax.sound

I need to know whether a ".wav" of 8bits, is signed or unsigned PCM, by only reading file. I cannot use "javax.sound.sampled.*" or AudioSystem libraries.
joseluisbz
  • 1,491
  • 1
  • 36
  • 58
6
votes
2 answers

Is it safe to assign -1 to an unsigned int to get the max value?

Is it safe to assign -1 to an unsigned int, or other unsigned c++ data type, if I need to get the max value? Is there any situation where it won't give me the highest value an unsigned data type can contain?
Spectralist
  • 225
  • 2
  • 7
5
votes
2 answers

unsigned overflow with modulus operator in C

i encountered a bug in some c code i wrote, and while it was relatively easy to fix, i want to be able to understand the issue underlying it better. essentially what happened is i had two unsigned integers (uint32_t, in fact) that, when the modulus…
david
  • 139
  • 1
  • 1
  • 9
5
votes
3 answers

c++: how to create unsigned char from UTF-8 code point

I'm working with a C++ library, and need to create an unsigned char from a UTF-8 code point. For example, if the code point is decimal 610 (a 'latin letter small capital G'), how would I create this in C++? I javascript, I can do the following: var…
FredL
  • 1,035
  • 9
  • 23
5
votes
4 answers

C++: Signed/unsigned mismatch when only using unsigned types

When I try to compile the following C++ program using the Visual Studio 2010 C++ compiler (X86) with warning level /W4 enabled, I get a signed/unsigned mismatch warning at the marked line. #include #include #include int…
Nubok
  • 3,502
  • 7
  • 27
  • 47
5
votes
1 answer

Why does gcc give a warning saying that the constant is unsigned because it is too large, when it is of the type __int128 and is signed?

Consider the following code: #include int main(void) { printf("%llu\n", 18446744073709551615); printf("%llu\n", 18446744073709551615ULL); return 0; } Upon compilation (gcc -std=c18), I get the following warnings: test1.c: In…
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
5
votes
0 answers

How to deal with potentially mixed signed and unsigned arithmetic in generic code?

The canonical example for mixed signed and unsigned arithmetic seems to be: unsigned int u = 10; int a = -42; auto tmp1 = u - a; std::cout << tmp1 << std::endl; int tmp2 = tmp1; std::cout << tmp2 << std::endl; (Note…
Oliver Schönrock
  • 1,038
  • 6
  • 11
5
votes
1 answer

Bit shift with a signed int resets one bit too much

Please have a look at the following code snippet, which basically simply bit shifts 1 byte by 24 bits to the left. uint64_t i = 0xFFFFFFFF00000000; printf("before: %016llX \n", i); i += 0xFF << 24; printf("after : %016llX \n", i); // gives: //…
geohei
  • 696
  • 4
  • 15
5
votes
1 answer

Why is FileInfo.Length of type "long"?

I was just wondering whether anyone knows why the property FileInfo.Length is of type long instead of ulong? I don't think the size of a file can ever be negative. Was this a general design decision for the .NET framework, since other length…
M4N
  • 94,805
  • 45
  • 217
  • 260
5
votes
2 answers

Why is Rust's usize to u128 conversion considered failable?

Take a look: use std::convert::{From, TryFrom}; fn main() { let size: usize = 42; let good: u128 = u128::try_from(size).unwrap(); // works fine let bad: u128 = u128::from(size); // doesn't compile! } As far as I know, usize…
passing_through
  • 1,778
  • 12
  • 24
5
votes
1 answer

char * vs unsigned char* what is the difference?

In Linux with c , I didn't understant what is the diffrence between char* and unsigned char* When I reading/writing binary buffer ? When I must not using char* and need to use unsigned char*?
parser1234
  • 111
  • 1
  • 7
5
votes
5 answers

What is the exact value range for unsigned long?

I am working through the exercises in the book "Learn C the hard way". Exercise 7 asks the reader to find the value which makes the range of an unsigned long exceed. Change long to unsigned long and try to find the number that makes it too big.…
チーズパン
  • 2,752
  • 8
  • 42
  • 63
5
votes
3 answers

Why can I pass an int with a value higher than 127 into a char array, but not directly?

I understand that a char value cannot be represented as 176, but some byte systems are unsigned (0-255) while others are signed (-128 to 127). In this case I'm working with unsigned, so I just wanted to create a simple byte message array, but I get…
karamazovbros
  • 950
  • 1
  • 11
  • 40
5
votes
2 answers

Is there a specification for a floating point’s exponent bias?

IEEE floating point exponents are stored as unsigned integers, using a pre-defined exponent bias to offset the exponent. The exponent bias seems to be consistently equal to numeric_limits::max_exponent - 1 where T is the floating point type. I do…
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
5
votes
1 answer

What is the math behind * 1233 >> 12 in this code counting decimal digits

I am a bit confused how this short function from the C++ {fmt} library works. inline std::uint32_t digits10_clz(std::uint32_t n) { std::uint32_t t = (32 - __builtin_clz(n | 1)) * 1233 >> 12; return t - (n < powers_of_10_u32[t]) + 1; } I…
NoSenseEtAl
  • 28,205
  • 28
  • 128
  • 277