This post details a similar issue as you've run into:
https://bytes.com/topic/visual-basic-net/answers/349731-integer-byte
It seems that Visual Basic performs overflow checking by default. This is why you are seeing the overflow exception.
Visual Basic is not really intended for low-level data manipulation, so it tries to protect the programmer from doing it. This, of course, makes it much harder when you actually need to perform low-level data manipulation using the language.
Try changing the following two lines
to this single line
What the line above does is shifts out all unused bits (24 of them, since you are using the Integer data type, which is 32-bits) and then shifts the 8 bits we care about to their final position (bits 23...16) while sign-extending the 8-bit value into a 16-bit value (located at bits 31...16). Note that Visual Basic uses an arithmetic shift for this operation, so if the 8-bit value is negative, the bits shifted in will be a value of 1, otherwise the bits shifted in will be 0.
https://bytes.com/topic/visual-basic-net/answers/349731-integer-byte
It seems that Visual Basic performs overflow checking by default. This is why you are seeing the overflow exception.
Visual Basic is not really intended for low-level data manipulation, so it tries to protect the programmer from doing it. This, of course, makes it much harder when you actually need to perform low-level data manipulation using the language.
Try changing the following two lines
mantissa = CSByte(Registers(1))
mantissa = mantissa << 16
to this single line
mantissa = (Registers(1) << 24) >> 8
What the line above does is shifts out all unused bits (24 of them, since you are using the Integer data type, which is 32-bits) and then shifts the 8 bits we care about to their final position (bits 23...16) while sign-extending the 8-bit value into a 16-bit value (located at bits 31...16). Note that Visual Basic uses an arithmetic shift for this operation, so if the 8-bit value is negative, the bits shifted in will be a value of 1, otherwise the bits shifted in will be 0.