12,999,157 members (43,566 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
 RickZeeland 116 Jochen Arndt 90 Dave Kreskowiak 60 Raghu112 50 OriginalGriff 40
 OriginalGriff 4,537 ppolymorphe 2,272 RickZeeland 2,057 Kornfeld Eliyahu Peter 1,973 Richard Deeming 1,593