本文共 2577 字,大约阅读时间需要 8 分钟。
c# 字节往前移6个字节
A single byte can store 8-bits value. Both are used for byte type of data i.e. the data that contains an only 1-byte value.
一个字节可以存储8位值。 两者均用于字节类型的数据,即仅包含1字节值的数据。
byte is used to work with unsigned byte data, it works with an only positive value between in the range of 0 to 255.
byte用于处理无符号字节数据 ,它的唯一正值在0到255之间 。
sbyte is used to work with the signed byte data, it works with both types of data (Negative and Positive), it can store the between in the range of -128 to 127.
sbyte用于处理带符号的字节数据 ,它适用于两种类型的数据(负数据和正数据),它可以存储介于-128到127之间的数据 。
byte | sbyte |
---|---|
byte stands for unsigned byte. | sbyte stands for signed byte. |
It can store positive bytes only. | It can store negative and positive bytes. |
It takes 8-bits space in the memory. | It also takes the 8-bits in the memory. |
Its data range is 0 to 255 that means it can store a minimum value 0 and maximum upto 255. | Its data range is -128 to 127 that means it can store a minimum value -128 and maximum upto 127. |
Declaration syntax:byte variable; | Declaration syntax:sbyte variable; |
字节 | 兆字节 |
---|---|
byte代表无符号字节。 | sbyte代表有符号字节。 |
它只能存储正字节。 | 它可以存储负字节和正字节。 |
它在内存中占用8位空间。 | 它还占用存储器中的8位。 |
它的数据范围是0到255,这意味着它可以存储最小值0和最大值,最多255。 | 它的数据范围是-128到127,这意味着它可以存储最小值-128和最大值,最多127。 |
声明语法: 字节变量; | 声明语法: sbyte变量; |
Example:
例:
Declaring signed and unsigned byte variable, assigning them with the values and printing the values.
声明有符号和无符号字节变量,为它们分配值并打印值。
using System;using System.Text;namespace ConsoleApplication3{ class Program { static void Main(string[] args) { byte a; sbyte b; //printing minimum & maximum values Console.WriteLine("Minimum value of byte: " + byte.MinValue); Console.WriteLine("Maximum value of byte: " + byte.MaxValue); Console.WriteLine("Minimum value of sbyte: " + sbyte.MinValue); Console.WriteLine("Maximum value of sbyte: " + sbyte.MaxValue); a = 0; Console.WriteLine("a = " + a); a = 255; Console.WriteLine("a = " + a); b = -100; Console.WriteLine("b = " + b); b = 123; Console.WriteLine("b = " + b); b = 127; Console.WriteLine("b = " + b); //hit ENTER to exit Console.ReadLine(); } }}
Output
输出量
Minimum value of byte: 0Maximum value of byte: 255Minimum value of sbyte: -128Maximum value of sbyte: 127a = 0a = 255b = -100b = 123b = 127
Read more:
阅读更多:
翻译自:
c# 字节往前移6个字节
转载地址:http://iwozd.baihongyu.com/