473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Convert byte to sbyte - no easy way?

I need to convert a byte to an sbyte - and it has to preserve the
original binary meaning of the 8 bits. For example - a 1111 1111,
which is interpreted as byte to be 255, should show up in the sbyte as
-1. The BitConverter class only takes 2 byte arrays or larger, and
the Convert.ToSByte simply throws an overflow error. Any ideas?

Thanks,
Ray Ackley
Nov 15 '05 #1
2 24675
byte b = 0xFF;
sbyte sb = unchecked((sbyte)b);

--
--Grant
This posting is provided "AS IS" with no warranties, and confers no rights.
Nov 15 '05 #2
"Grant Richins [MS]" <gr*****@online.microsoft.com> wrote in message news:<uq**************@tk2msftngp13.phx.gbl>...
byte b = 0xFF;
sbyte sb = unchecked((sbyte)b);

Thanks! That worked great.

Ray Ackley
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: David Levine | last post by:
Using v1.1. of the framework: I was writing a wrapper around the java.util.zip.ZipOutputStream class so that my app could access it using standard FileStream semantics and I ran into a...
2
by: [Gho] | last post by:
How to convert a Hexa value to negative and non negative value : if i get 0x1d = result should be 29 but if i get fd = result should be -3 How to do that
5
by: _Andy_ | last post by:
I'm looking for the alogithm to take a piece of 8-bit audio data, and scale it to a 16-bit short. I got as far as: private static short ByteToShort(byte b) { int word = 0; word |= ( ( b &...
1
by: Darrel | last post by:
I am using binary writer to write an array of bytes to disk. However, my data starts out as an array of sbytes. I am currently type casting each array element in a for loop. Is there a faster...
2
by: jiangyh | last post by:
hi there : I have a question about how to convert Type to DbType? thanks a lot. jiangyh
1
by: G.M. Harland | last post by:
Please keep in mind that I am a PowerBuilder developer working on his first ..NET project. I have a VB.NET console app that is responsible for taking MS Word docs and getting them into an Oracle...
3
by: reju | last post by:
I have to convert an sByte array to byte array. This sbyte array contains some signed values due to this .net converting functions will throw an exception.any work around for this? is there any...
0
by: hillman | last post by:
Hello, Maestros. Following on from the posts on creating structs from a byte. The methods described there work well. But I seem to have struck a snag that some might find interesting. The C/C++...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.