This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
vba:cast:bitandbyte [30.04.2014 11:25:18] yaslaw |
vba:cast:bitandbyte [29.04.2015 11:15:38] (current) yaslaw |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== [VBA] bitArray() char2byte() und byte2char()====== | + | ====== [VBA] bitArray(), char2byte() und byte2char()====== |
- | Drei Funktionen im Umgang mit Bits. | + | //Drei Funktionen im Umgang mit Bits.// |
+ | |||
+ | {{:vba:cast:bitandbyte.bas|Download bitAndBytes.bas Version 1.0}} | ||
+ | |||
- bitArray() zerlegt ein Zahl in ihre Bit-Teile. Ist also das Rekusive zu 1+2+4+8+... | - bitArray() zerlegt ein Zahl in ihre Bit-Teile. Ist also das Rekusive zu 1+2+4+8+... | ||
- Mit char2byte() kann man die Bit-Darstellung eines Zeichens ermitteln | - Mit char2byte() kann man die Bit-Darstellung eines Zeichens ermitteln | ||
Line 31: | Line 35: | ||
Optional ByVal iValueType As baValueType = baBit, _ | Optional ByVal iValueType As baValueType = baBit, _ | ||
Optional ByVal iFilteredOut As Boolean = False _ | Optional ByVal iFilteredOut As Boolean = False _ | ||
- | ) As Variant()</vb> | + | ) As Variant()</code> |
***iNumber** Die Nummer, welche 'zerlegt' werden soll | ***iNumber** Die Nummer, welche 'zerlegt' werden soll | ||
***iValueType** Art des Inhalt des Array. | ***iValueType** Art des Inhalt des Array. | ||
Line 62: | Line 66: | ||
) | ) | ||
</code> | </code> | ||
- | ====Code==== | + | |
+ | =====char2byte()===== | ||
+ | |||
+ | ====Definition==== | ||
+ | <code vb> | ||
+ | Public Function char2byte( | ||
+ | ByVal iChar As Variant, | ||
+ | Optional iBitCode As baBitCode = baDefault | ||
+ | ) As String | ||
+ | </code> | ||
+ | ***iChar** Charakter, der gewandelt werden soll. Null wird als 0 gewertet | ||
+ | ***iBitCode** Die Codierung. baAscii oder ba BCD | ||
+ | |||
+ | ====Beispiele==== | ||
+ | <code vb> | ||
+ | 'example 1) Byte einer Zahl. Zahlen sind tandart nach BCD-Codierung | ||
+ | print_r getByte(9) | ||
+ | <String> '1001' | ||
+ | |||
+ | 'example 2) Dito, aber nach ASCII-Codierung | ||
+ | print_r getByte(9, baASCII) | ||
+ | <String> '10011100' | ||
+ | |||
+ | 'example 3) String, Standart nach Ascii | ||
+ | print_r getByte("A") | ||
+ | <String> '10000010' | ||
+ | |||
+ | 'example 4) Null, Standart nach Ascii | ||
+ | print_r getByte(Null, baBCD) | ||
+ | <String> '00000000' | ||
+ | |||
+ | 'example 5) Null nach BCD | ||
+ | print_r getByte(Null) | ||
+ | <String> '0000' | ||
+ | </code> | ||
+ | |||
+ | =====byte2char()===== | ||
+ | |||
+ | ====Definition==== | ||
+ | <code>Public Function byte2char(ByVal iByte As String) As Variant</code> | ||
+ | ***iByte** Byte, das in ein Charakter gewandelt werden soll | ||
+ | |||
+ | ====Beispiele==== | ||
+ | <code vb> | ||
+ | 'example 1) Byte einer Zahl. Zahlen sind tandart nach BCD-Codierung | ||
+ | print_r getChar("1001") | ||
+ | <Integer> 9 | ||
+ | |||
+ | 'example 2) Dito, aber nach ASCII-Codierung | ||
+ | print_r getChar("10011100") | ||
+ | <String> '9' | ||
+ | |||
+ | 'example 3) String, Standart nach Ascii | ||
+ | print_r getChar("10000010") | ||
+ | <String> 'A' | ||
+ | |||
+ | 'example 4) Null, Standart nach Ascii. Es kommt die Rückgabe von chr(NULL) zurück | ||
+ | print_r getChar("00000000") | ||
+ | <String> '\u0000' | ||
+ | |||
+ | 'example 5) Null nach BCD. Ist nciht mehr von 0 unterscheidbar | ||
+ | print_r getChar("0000") | ||
+ | <Integer> 0 | ||
+ | </code> | ||
+ | |||
+ | =====Codes===== | ||
+ | ====Code bitArray()==== | ||
<code vb> | <code vb> | ||
'/** | '/** | ||
Line 103: | Line 173: | ||
bitArray = retArray | bitArray = retArray | ||
End Function | End Function | ||
- | <code> | ||
- | |||
- | =====char2byte()===== | ||
- | |||
- | ====Definition==== | ||
- | <code vb> | ||
- | Public Function char2byte( | ||
- | ByVal iChar As Variant, | ||
- | Optional iBitCode As baBitCode = baDefault | ||
- | ) As String | ||
</code> | </code> | ||
- | ***iChar** Charakter, der gewandelt werden soll. Null wird als 0 gewertet | ||
- | ***iBitCode** Die Codierung. baAscii oder ba BCD | ||
- | ====Beispiele==== | + | ====Code char2byte==== |
- | <code vb> | + | |
- | 'example 1) Byte einer Zahl. Zahlen sind tandart nach BCD-Codierung | + | |
- | print_r getByte(9) | + | |
- | <String> '1001' | + | |
- | + | ||
- | 'example 2) Dito, aber nach ASCII-Codierung | + | |
- | print_r getByte(9, baASCII) | + | |
- | <String> '10011100' | + | |
- | + | ||
- | 'example 3) String, Standart nach Ascii | + | |
- | print_r getByte("A") | + | |
- | <String> '10000010' | + | |
- | + | ||
- | 'example 4) Null, Standart nach Ascii | + | |
- | print_r getByte(Null, baBCD) | + | |
- | <String> '00000000' | + | |
- | + | ||
- | 'example 5) Null nach BCD | + | |
- | print_r getByte(Null) | + | |
- | <String> '0000' | + | |
- | </code> | + | |
- | + | ||
- | ====Code==== | + | |
<code vb> | <code vb> | ||
'/** | '/** | ||
Line 175: | Line 210: | ||
</code> | </code> | ||
- | =====byte2char()===== | + | ====Code byte2char== |
- | + | ||
- | ====Definition==== | + | |
- | <code>Public Function byte2char(ByVal iByte As String) As Variant</code> | + | |
- | ***iByte** Byte, das in ein Charakter gewandelt werden soll | + | |
- | + | ||
- | ====Beispiele==== | + | |
- | <code> | + | |
- | 'example 1) Byte einer Zahl. Zahlen sind tandart nach BCD-Codierung | + | |
- | print_r getChar("1001") | + | |
- | <Integer> 9 | + | |
- | + | ||
- | 'example 2) Dito, aber nach ASCII-Codierung | + | |
- | print_r getChar("10011100") | + | |
- | <String> '9' | + | |
- | + | ||
- | 'example 3) String, Standart nach Ascii | + | |
- | print_r getChar("10000010") | + | |
- | <String> 'A' | + | |
- | + | ||
- | 'example 4) Null, Standart nach Ascii. Es kommt die Rückgabe von chr(NULL) zurück | + | |
- | print_r getChar("00000000") | + | |
- | <String> '\u0000' | + | |
- | + | ||
- | 'example 5) Null nach BCD. Ist nciht mehr von 0 unterscheidbar | + | |
- | print_r getChar("0000") | + | |
- | <Integer> 0 | + | |
- | </code> | + | |
- | + | ||
- | ====Code==== | + | |
<code vb> | <code vb> | ||
'/** | '/** |