Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

C# Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(C#) Encode Integer to Hex or Base64 using N Bytes

Demonstrates how to write an integer to N bytes (little-endian or big-endian) and return the bytes in any encoding such as hex, base64, etc.

Note: This example requires Chilkat v9.5.0.77 or greater.

Chilkat .NET Downloads

Chilkat .NET Assemblies

Chilkat for .NET Core

Chilkat for Mono

Chilkat.Crypt2 crypt = new Chilkat.Crypt2();

// 1193046 decimal is equal to 0x123456 hex.
int value = 1193046;

// Write the integer in 8 bytes using little-endian byte-order and return as hex
bool bLittleEndian = true;
string s = crypt.EncodeInt(value,8,bLittleEndian,"hex");
// The output is: 5634120000000000
Debug.WriteLine(s);

// Now use big-endian...
bLittleEndian = false;
s = crypt.EncodeInt(value,8,bLittleEndian,"hex");
// The output is: 0000000000123456
Debug.WriteLine(s);

// Instead of hex, get the 8 bytes using base64.
s = crypt.EncodeInt(value,8,bLittleEndian,"base64");
// The output is: AAAAAAASNFY=
Debug.WriteLine(s);

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.