Questions tagged [sbyte]
10 questions
2
votes
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
- 35
- 1
- 6
1
vote
1 answer
Why is unsafe read sbyte -> byte inconsistent in Release mode: *(byte*)(&sbyteValue)?
While writing conversion of generic enum to int strange things happened around unsafe read of sbyte type to byte.
The folloging examples were tested with .Net 6.0 on AMD x64 machine.
Example 1: Inconsistency Debug vs. Release
The following code…

frakon
- 1,948
- 2
- 22
- 26
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…

TheRealDuBoySem
- 13
- 4
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
- 839
- 9
- 13
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
- 23,309
- 10
- 44
- 76
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
- 21
- 8
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
- 33,575
- 33
- 102
- 171
-1
votes
1 answer
Convert int to sbyte in C#
I recently bought some Bluetooth LE Devices and wanted to read the Data coming from them in Unity. The Problem is I used a library that gives me only a byte array. But I need a sbyte Array.
Example output:
83,186,1,3
But I want: 38, -70,1,3
Here is…

TikTokExperience
- 15
- 2
-1
votes
2 answers
A convert back from the given string into byte/sbyte
I have a function which form a string like this
public static string formString(sbyte myByte)
{
try
{
var str = string.Empty;
for (int i = 0; i <= 7; i++)
{
if(( (1<

Cagaya Coper
- 75
- 1
- 12
-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…

ChristAHFER
- 5
- 4