Để chuyển đổi qua lại giữa các hệ cơ số trong lập trình C# bạn có thể tham khảo các phương thức sau đây.

Bài liên quan
Hexadecimal, Decimal, Octal, Binary


1. Hex

a.) Decimal

//Hex to Dec
var hex = "7E0";
var dec = Convert.ToInt32(hex, 16); //2016
//Dec to Hex
var hex2 = dec.ToString("X"); //7E0

b.) Octal

//Hex to Octal
var hex = "7E0";
var dec = Convert.ToInt32(hex,16); //2016
var oct = Convert.ToString(dec,8); //3740
//Octal to Hex
var dec2 = Convert.ToInt32(oct, 8); //2016
var hex2 = dec2.ToString("X"); //7E0

c.) Bin

//Hex to Bin
var hex = "7E0";
var dec = Convert.ToInt32(hex,16); //2016
var bin = Convert.ToString(dec,2); //0111 1110 0000
//Bin to Hex
var dec2 = Convert.ToInt32(bin, 2); //2016
var hex2 = dec2.ToString("X"); //7E0

2. Dec

a. Octal

//Dec to Octal
var dec = 2016;
var oct = Convert.ToString(dec,8); //3740
//Octal to Dec
var dec2 = Convert.ToInt32(oct, 8); //2016

b. Bin

//Dec to Bin
var dec = 2016;
var bin = Convert.ToString(dec,2); //0111 1110 0000
//Bin to Dec
var dec2 = Convert.ToInt32(bin, 2); //2016


3. Octal

//Oct to Bin
var oct = "3740";
var dec = Convert.ToInt32(oct,8); //2016
var bin = Convert.ToString(dec, 2); //0111 1110 0000
//Bin to Oct
var dec2 = Convert.ToInt32(bin, 2); //2016
var oct2= Convert.ToString(dec2, 8); //3740


Created: 21/04/2016

thumbnail [C# .NET] Convert Between Hexadecimal, Decimal, Octal, Binary With C#

data:label.name author

premiumpng.com

Design Publisher

Download 0
No comments
Template in .PSD format

MR Laboratory License

Free for personal purpose use . More info


Buy Now This Template

No comments:

Post a Comment

Commets Download Photoshop Actions, Lightroom Presets, PSD Template, Mockups, Stocks, Vectors, Fonts. Download free

Newer Post Older Post Home

Copyright © 2021 MR Laboratory All rights reserved.

Setting