Questions tagged [sbyte]

8 questions
1
vote
1 answer

Why casting big double value in sbyte returns 0 in C#?

I actually test the casting behavior in C# in unchecked context. Like the documentation said, in unchecked context, the cast always succeed. But sometimes, in particular cases, the cast from one specific type to another type give unexpected…
1
vote
1 answer

Why [1111 1111] represents as -1 but not 255 in Integer?

I do a number sign replacement according to the rule: invert bit by bit, and add 1, but I work with an integer data type not sbyte. How does the compiler understand that I am changing the sign, and not returning the value 255? int operand1…
Pobaranchuk
  • 165
  • 2
  • 5
1
vote
2 answers

How can I pass a C# String-like variable to a sbyte* parameter?

I inherited a C++ DLL with its related header file, with functions declared like int func1(int i); int func2(char* s); I also inherited a reference VC++ reference class that wraps the above DLL to be used in C# environment public ref class…
Daniele Nardi
  • 25
  • 1
  • 5
1
vote
1 answer

Simplify if-clauses when checking for range and setting default value

I have a function that converts a double value into the sbyte and returns its hex representation: string convertToSByte(double num, double factor) { double _Value = num * factor; if (_Value > 127) { _Value = 127; } else…
Mong Zhu
  • 20,890
  • 7
  • 33
  • 66
0
votes
0 answers

Udp sbyte send/receive

I am communicating with a device in UDP, I send byte type values ​​from 0 to 255 and some Sbyte type values ​​from -128 to +127. my question arises in relation to the Sbyte type value. How I can send them via UDP while the UDPclient only takes a…
0
votes
0 answers

Assigning a year value to sbyte

I am using a function which is present in a library which I cannot modify. That function is used to set the Date by the user. Its parameters are SetDate(sbyte day, sbyte month, sbyte year) When I assign 2019. I want to assign 2019 to sbyte year.…
chaudhry
  • 37
  • 7
0
votes
1 answer

How -128 fits in a sbyte

As I remember we had learned that signed integer types (sbyte, short, int , long) the first bit is for the sign and the latter 7 bit is for the value. I saw that sbyte range is -128 to 127 while I thought it must be -127 to 127. I tried some codes…
Ashkan Mobayen Khiabani
  • 30,915
  • 26
  • 90
  • 147
-3
votes
1 answer

Creating 100 variables

So I created an array with 100 variables using Enumerable.Range. The data type is limited to Int32. Problem How can I create the same array with SByte? Am I right in thinking I would need to use a loop to create and index the variables? I have…