.NET/符号付バイトsbyte,符号なしbyteをintegerに変換する
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
#navi(../)
* 符号付バイトsbyte,符号なしbyteをintegerに変換する [#ac3...
byte, sbyte, byte[], sbyte[] を integer に変換するサンプ...
Convert.ToInt32, byte[].GetValue(index), sbyte[].GetValue...
#contents
* 関連サイト [#sbf7c674]
-[[Microsoft .NET | Convert.ToInt32 メソッド>https://docs...
-[[Microsoft .NET | Array.GetValue メソッド>https://docs....
#htmlinsert(windev-top.html)
* 動作確認環境 [#pc9874fa]
-Windows 10 ver.1909
-Visual Studio 2019
-.NET Core
-コンソールアプリケーション
* byte, sbyte -> integer 変換サンプルコード [#kbb17e6c]
以下にbyte, sbyte を integer に変換するサンプルコードを紹...
符号なし、符号付き、符号なしの配列、符号付きの配列を inte...
** C# [#uac1953a]
#ref(Program.cs)
using System;
class Program
{
static void Main(string[] args)
{
int i;
// signed byte
Console.WriteLine("*** signed byte ***");
Console.WriteLine("-- System.Convert.ToInt32() -...
sbyte sb;
sb = 123;
i = Convert.ToInt32(sb);
Console.WriteLine(i);
sb = -123;
i = Convert.ToInt32(sb);
Console.WriteLine(i);
sbyte[] sb_ary = { 10, -20, 30, -40 };
Console.WriteLine("-- foreach and System.Convert...
foreach (sbyte s in sb_ary)
{
Console.WriteLine(Convert.ToInt32(s));
}
Console.WriteLine("-- foreach and sbyte[].GetVal...
for (int j = 0; j < sb_ary.Length; j++)
{
Console.WriteLine(sb_ary.GetValue(j));
}
// unsigned byte
Console.WriteLine("*** unsigned byte ***");
Console.WriteLine("-- System.Convert.ToInt32() -...
byte b;
b = 200;
i = Convert.ToInt32(b);
Console.WriteLine(i);
byte[] b_ary = { 0, 10, 100, 200, 255 };
Console.WriteLine("-- foreach and System.Convert...
foreach (byte ub in b_ary)
{
Console.WriteLine(Convert.ToInt32(ub));
}
Console.WriteLine("-- foreach and byte[].GetValu...
for (int k = 0; k < b_ary.Length; k++)
{
Console.WriteLine(b_ary.GetValue(k));
}
}
}
** Visual Basic [#w5c2307d]
#ref(Program.vb)
Imports System
Module Program
Sub Main(args As String())
Dim i As Integer
Console.WriteLine("*** signed byte ***")
Console.WriteLine("-- System.Convert.ToInt32() -...
Dim sb As SByte
sb = 123
i = Convert.ToInt32(sb)
Console.WriteLine(i)
sb = -123
i = Convert.ToInt32(sb)
Console.WriteLine(i)
Dim sb_ary As SByte() = {10, -20, 30, -40}
Console.WriteLine("-- foreach and System.Convert...
For Each s As SByte In sb_ary
Console.WriteLine(Convert.ToInt32(s))
Next
Console.WriteLine("-- foreach and sbyte[].GetVal...
For j As Integer = 0 To sb_ary.Length - 1
Console.WriteLine(sb_ary.GetValue(j))
Next
Console.WriteLine("*** unsigned byte ***")
Console.WriteLine("-- System.Convert.ToInt32() -...
Dim b As Byte
b = 200
i = Convert.ToInt32(b)
Console.WriteLine(i)
Dim b_ary As Byte() = {0, 10, 100, 200, 255}
Console.WriteLine("-- foreach and System.Convert...
For Each ub As Byte In b_ary
Console.WriteLine(Convert.ToInt32(ub))
Next
Console.WriteLine("-- foreach and byte[].GetValu...
For k As Integer = 0 To b_ary.Length - 1
Console.WriteLine(b_ary.GetValue(k))
Next
End Sub
End Module
** 実行結果 [#y4e2320e]
上記のサンプルコードを実行した時のキャプチャになります。
#ref(run.png)
以上、byte, sbyte, byte[], sbyte[] を integer に変換する...
#htmlinsert(windev-btm.html)
終了行:
#navi(../)
* 符号付バイトsbyte,符号なしbyteをintegerに変換する [#ac3...
byte, sbyte, byte[], sbyte[] を integer に変換するサンプ...
Convert.ToInt32, byte[].GetValue(index), sbyte[].GetValue...
#contents
* 関連サイト [#sbf7c674]
-[[Microsoft .NET | Convert.ToInt32 メソッド>https://docs...
-[[Microsoft .NET | Array.GetValue メソッド>https://docs....
#htmlinsert(windev-top.html)
* 動作確認環境 [#pc9874fa]
-Windows 10 ver.1909
-Visual Studio 2019
-.NET Core
-コンソールアプリケーション
* byte, sbyte -> integer 変換サンプルコード [#kbb17e6c]
以下にbyte, sbyte を integer に変換するサンプルコードを紹...
符号なし、符号付き、符号なしの配列、符号付きの配列を inte...
** C# [#uac1953a]
#ref(Program.cs)
using System;
class Program
{
static void Main(string[] args)
{
int i;
// signed byte
Console.WriteLine("*** signed byte ***");
Console.WriteLine("-- System.Convert.ToInt32() -...
sbyte sb;
sb = 123;
i = Convert.ToInt32(sb);
Console.WriteLine(i);
sb = -123;
i = Convert.ToInt32(sb);
Console.WriteLine(i);
sbyte[] sb_ary = { 10, -20, 30, -40 };
Console.WriteLine("-- foreach and System.Convert...
foreach (sbyte s in sb_ary)
{
Console.WriteLine(Convert.ToInt32(s));
}
Console.WriteLine("-- foreach and sbyte[].GetVal...
for (int j = 0; j < sb_ary.Length; j++)
{
Console.WriteLine(sb_ary.GetValue(j));
}
// unsigned byte
Console.WriteLine("*** unsigned byte ***");
Console.WriteLine("-- System.Convert.ToInt32() -...
byte b;
b = 200;
i = Convert.ToInt32(b);
Console.WriteLine(i);
byte[] b_ary = { 0, 10, 100, 200, 255 };
Console.WriteLine("-- foreach and System.Convert...
foreach (byte ub in b_ary)
{
Console.WriteLine(Convert.ToInt32(ub));
}
Console.WriteLine("-- foreach and byte[].GetValu...
for (int k = 0; k < b_ary.Length; k++)
{
Console.WriteLine(b_ary.GetValue(k));
}
}
}
** Visual Basic [#w5c2307d]
#ref(Program.vb)
Imports System
Module Program
Sub Main(args As String())
Dim i As Integer
Console.WriteLine("*** signed byte ***")
Console.WriteLine("-- System.Convert.ToInt32() -...
Dim sb As SByte
sb = 123
i = Convert.ToInt32(sb)
Console.WriteLine(i)
sb = -123
i = Convert.ToInt32(sb)
Console.WriteLine(i)
Dim sb_ary As SByte() = {10, -20, 30, -40}
Console.WriteLine("-- foreach and System.Convert...
For Each s As SByte In sb_ary
Console.WriteLine(Convert.ToInt32(s))
Next
Console.WriteLine("-- foreach and sbyte[].GetVal...
For j As Integer = 0 To sb_ary.Length - 1
Console.WriteLine(sb_ary.GetValue(j))
Next
Console.WriteLine("*** unsigned byte ***")
Console.WriteLine("-- System.Convert.ToInt32() -...
Dim b As Byte
b = 200
i = Convert.ToInt32(b)
Console.WriteLine(i)
Dim b_ary As Byte() = {0, 10, 100, 200, 255}
Console.WriteLine("-- foreach and System.Convert...
For Each ub As Byte In b_ary
Console.WriteLine(Convert.ToInt32(ub))
Next
Console.WriteLine("-- foreach and byte[].GetValu...
For k As Integer = 0 To b_ary.Length - 1
Console.WriteLine(b_ary.GetValue(k))
Next
End Sub
End Module
** 実行結果 [#y4e2320e]
上記のサンプルコードを実行した時のキャプチャになります。
#ref(run.png)
以上、byte, sbyte, byte[], sbyte[] を integer に変換する...
#htmlinsert(windev-btm.html)
ページ名: