VB: 2's Complement on Byte - Function & Binary Conversion

  • Thread starter Thread starter ionlylooklazy
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on performing 2's complement on a byte using bitwise operations in C# and VB.Net. To achieve this, one must convert the byte or character to an integer, apply the bitwise NOT operator (~ in C# and Not in VB.Net), and then add 1 to the result. The provided code snippets demonstrate the implementation in both programming languages, ensuring clarity in the conversion process.

PREREQUISITES
  • Understanding of bitwise operations in programming
  • Familiarity with C# and VB.Net syntax
  • Knowledge of data types, specifically byte and integer conversions
  • Basic programming concepts related to arithmetic operations
NEXT STEPS
  • Explore bitwise operations in C# and VB.Net
  • Learn about data type conversions in C# and VB.Net
  • Investigate the implications of 2's complement in binary arithmetic
  • Study error handling when performing bitwise operations on different data types
USEFUL FOR

Software developers, particularly those working with low-level data manipulation in C# and VB.Net, as well as anyone interested in understanding binary arithmetic and 2's complement operations.

ionlylooklazy
Messages
30
Reaction score
0
is there a function available that will perform 2's complement on a byte?
or a way to convert a byte or char to binary so I can do the operation myself?

thanks,
ioll
 
Technology news on Phys.org
It should be pretty simple. All you need to do is perform a bitwise NOT and then add a 1. You would convert your byte or char to an Int, perform the bitwise Not, and then add a 1. In C# the ~ is the bitwise NOT, so you would do:
Code:
int b = 230;
int bAfter2sC = ~b + 1

In VB.Net try:
Code:
Dim b As Integer
Dim bAfter2sC As Integer
bAfter2sC = Not(b) + 1
 
Last edited:
thank you very much again!
 

Similar threads

Replies
5
Views
1K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 29 ·
Replies
29
Views
3K
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K