Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 2nd January 2012, 11:02   #1  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
BaseConvert.avsi | Encode/decode binary, octal, hex, Base16, Base32, Base64

I wrote this as an exercise/experiment to try to duplicate some functions from Perl and other scripting languages by using Gscript. I hope others find this useful also.

It allows you to convert integers to arbitrary bases (and vice versa) using "extended" hex notation as needed (up to Base-64). It also allows encoding/decoding of MIME Base64 and RFC 4648 Base32 strings.

You can also encode/decode Base16 (hex) 4-bit text strings.

Download here

Code:
############################################################################################
# BaseConvert.avsi
#
# 2012/01/03 -> Some code cleanup
# 2012/01/02 -> Added Base16
#            -> Documentation corrections
# 2012/01/02 -> First Release
############################################################################################
# Requires Gscript.dll
############################################################################################
# -----------------
# String Functions
# -----------------
# Ord(string c)
# -> Returns the ASCII value of a character as an integer
#
# encode_base64(string s, string "eol")
# -> Encodes a string to MIME Base64
# -> By default, lines are limited to 76 chars. Set eol="" to disable this.
#
# decode_base64(string s)
# -> Decodes a MIME Base64 string
#
# encode_base32(string s)
# -> Encodes an RFC 4648 Base32 string
#
# decode_base32(string s)
# -> Decodes an RFC 4648 Base32 string
#
# encode_base16(string s)
# -> Encodes a hexadecimal string
#
# decode_base16(string s)
# -> Decodes a hexadecimal string
# 
# -----------------
# Integer Functions
# -----------------
#
# DecimalToBase(int n, int b, int "MinLen")
# -> Converts a base-10 integer (n) to an arbitrary base (b) with optional padding (MinLen)
# -> The result is a numeric or alphanumeric string
# -> Example #1:Convert 255 to octal (377)
#    DecimalToBase(255, 8)
# -> Example #2:Convert 65535 to hexadecimal, 8 digits (00FFFF)
#    DecimalToBase(65535, 16, 8)
# -> Example #3:Convert 16 to binary(10000)
#    DecimalToBase(16, 2)
#
# BaseToDecimal(string s, base b)
# -> Convert a base number string to its base-10 value, returns integer
# -> Example #1: convert binary 10000 to decimal (16)
#    BaseToDecimal("10000", 2)
# -> Example #2:Convert hexadecimal FFFF to decimal 65535
#    DecimalToBase("FFFF", 16)
# -> Example #3: convert octal 377 to decimal (255)
#    BaseToDecimal("377", 8)
#
# Notes:
# ------
# DecimalToBase and BaseToDecimal use a [0-9,A-Z,a-z] alphabet
# encode_base32 and decode_base32 uses [A-Z,2-7]
# encode_base64 and decode_base64 uses [A-Z,a-z,0-9,+,/]
# Different chars can be specified for values 62 and 63 by setting the global variables
# __base_char62__ and __base_char63__ to any single-character strings (such as "-" and "_", for example)

Last edited by vampiredom; 3rd January 2012 at 19:01. Reason: updated
vampiredom is offline   Reply With Quote
Old 2nd January 2012, 21:59   #2  |  Link
tin3tin
Registered User
 
tin3tin's Avatar
 
Join Date: Mar 2005
Posts: 365
@ vampiredom - Please consider to collecting all your great scripts somewhere, so they do not just disappear some day among old threads.
__________________
DVD slideshow GUI(Freeware).
tin3tin is offline   Reply With Quote
Old 2nd January 2012, 23:56   #3  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
Quote:
Originally Posted by tin3tin View Post
@ vampiredom - Please consider to collecting all your great scripts somewhere, so they do not just disappear some day among old threads.
Aw, thanks! I will, I will ... eventually.
vampiredom is offline   Reply With Quote
Old 3rd January 2012, 19:34   #4  |  Link
vampiredom
Registered User
 
Join Date: Aug 2008
Posts: 233
I just posted a new version. Not really any functional changes, just some cleanup. If there is any other character encoding scheme you feel should be added, let me know.
vampiredom is offline   Reply With Quote
Reply

Tags
base, decode, encode, gscript, strings

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:32.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.