Let me first post some code before asking the question.
VB Code:
Other Language Codes:
C#
Java
Code after decompiling the byte code.
C#
Java
VB Code in C# Context
Now finally my question comes,
In all the cases, the code is treated as a integer, as far as i understand is this because the registers of the computer "prefer" to work with integers.
However, the VB.NET code actually gets "treated" as a byte,It is first casted to a byte, then the bit operation is applied (100 <<8 in a byte stays 100), then it is casted back to a integer
Why is this done? (in other words: Why does the VB.net byte "stays" as a byte and in Java,C# etc it doesn't)
VB Code:
Code:
Module Module1
Sub Main()
'
Dim s As Byte = 100
'
Console.WriteLine(s << 8) '100
Console.ReadLine()
End Sub
End Module
Other Language Codes:
C#
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte s = 100;
Console.WriteLine(s << 8); // 25600
Console.ReadLine();
}
}
}
Java
Code:
public static void main(String[] args) {
byte s = 100;
System.out.println(s<<8);
}
Code after decompiling the byte code.
C#
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(100 << 8); // 25600, treated as int
Console.ReadLine();
}
}
}
Java
Code:
public static void main(String[] args) {
System.out.println(100<<8);
}
VB Code in C# Context
Code:
internal sealed class Module1
{
[STAThread]
public static void Main()
{
Console.WriteLine((int) (byte) (100U << 0));
Console.ReadLine();
}
}
Now finally my question comes,
In all the cases, the code is treated as a integer, as far as i understand is this because the registers of the computer "prefer" to work with integers.
However, the VB.NET code actually gets "treated" as a byte,It is first casted to a byte, then the bit operation is applied (100 <<8 in a byte stays 100), then it is casted back to a integer
Why is this done? (in other words: Why does the VB.net byte "stays" as a byte and in Java,C# etc it doesn't)
Last edited:

