12,405,932 members (46,409 online)
Rate this:
See more:
this is the converting the int value to byte value
Posted 30-Mar-10 0:05am

Rate this:

## Solution 2

It's not possible. A byte is 0 to 255. An int is a whole lot bigger than that. So, you can convert an int to a stream of bytes, but not to a byte.
Rate this:

## Solution 3

Use Convert.ToByte(intValue) which will convert your integer value to byte. If the entered value is too big or too small, it will through OverFlowException.

Better to use the Byte.TryParse(...) method.
Rate this:

## Solution 1

int intValue = 2;

byte byteValue = Convert.ToByte(intValue);

This is what you're looking for?

As indeed pointed out below a byte goes until the number 255 and then stops because a byte can holds 8 bits

binary: 11111111 = 255
v3
Rate this:

## Solution 4

As already pointed out, generally speaking, an integer will not fit in a byte. Please post some context info (why do you need to perform such a conversion?) to get better help.
v2
Rate this:

## Solution 5

Maybe what you need is converting an integer to its byte representation? i.e. 4 bytes for 32 bits integers.

In order to do that, the framework provides the BitConverter class.

http://msdn.microsoft.com/en-us/library/system.bitconverter.aspx[^]

Top Experts
Last 24hrsThis month
 OriginalGriff 351 BillWoodruff 160 ppolymorphe 150 Karthik Bangalore 144 Richard Deeming 125
 OriginalGriff 7,747 ppolymorphe 3,380 Karthik Bangalore 3,321 Richard MacCutchan 2,472 F-ES Sitecore 2,300