Re: How do i change numerics into binary numbers?



So you want the binary 1/0 string for a given
number? You don't want Base64 conversion?

------------------------------------
Public Function Dec2Bin(ByVal DecimalIn As Long, _
Optional NumberOfBits As Variant) As String
Dec2Bin = ""
Do While DecimalIn <> 0
Dec2Bin = Trim$(Str$(DecimalIn Mod 2)) & Dec2Bin
DecimalIn = DecimalIn \ 2
Loop
If Not IsMissing(NumberOfBits) Then
If Len(Dec2Bin) > NumberOfBits Then
Dec2Bin = "Error - Number exceeds specified bit size"
Else
Dec2Bin = Right$(String$(NumberOfBits, _
"0") & Dec2Bin, NumberOfBits)
End If
End If
End Function
--------------------------

I think that code came from Karl Peterson's website:
http://vb.mvps.org/

It's worth a visit. Among other things he has a package
of sample code for all sorts of variations on bit/byte
manipulation:
http://vb.mvps.org/samples/project.asp?id=Twiddle

....
Does anyone know? pls help tks!

"Howk013" wrote:

Hi rick,
hmm..ok,

for example:

Bit 0-6 reserved for message identifier , so if the user keyed in
message 1,
which they get to choose from combo box, the code must be able to encode
it
using 6bit-ascii to get an output of "1" ( because 000 001 is 1 in 6bit
ascii conversion)

Subsequently,if bit lengths allocated are higher than 6 bits, they are
broken down into blocks of 6, to encode and get the output according to
6bit
table

The subsequent bits are used for other functions like latitudes and
longitudes etc. Which requires more than 6bits

so assuming 0-6 is used , and bit 7 ( is a "1") represent another
function
which is a switch, and bit 8 (is a "0") represent another function that
is
also another switch, while 9-38 indicates the number of an object (in
this
case, user input "127" which is 0000 0000 0000 0000 0000 0001 1111 11 )
, it
will look like this

000 001 ---------------------> 1
1(bit 7)0(bit 8)0 000---------> P
000 000-----------------------> 0
000 000-----------------------> 0
000 000-----------------------> 0
011 111-----------------------> O
11x xxx and so on

the right hand side represents the output i would like to obtain after
running the code. (which is conversion from the 6bit ascii table
basically)

Once again, thank you all for prompt replies!



"Rick Rothstein (MVP - VB)" wrote:

When the user input all the data of the 168bits

Exactly what is the user inputting (I presume it is a string of
characters)?
Show us an example of a typical user input.

Rick





.



Relevant Pages

  • Re: How do i change numerics into binary numbers?
    ... You don't want Base64 conversion? ... Public Function Dec2Bin(ByVal DecimalIn As Long, ... Optional NumberOfBits As Variant) As String ... Decimal data typed use by my function is 96 bits, ...
    (microsoft.public.vb.general.discussion)
  • Re: How do i change numerics into binary numbers?
    ... You don't want Base64 conversion? ... Public Function Dec2Bin(ByVal DecimalIn As Long, ... Optional NumberOfBits As Variant) As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Masking Double Variables
    ... > Dim cur As Variant ... string for the number, ... Function Dec2Bin(ByVal DecimalIn As Variant, ...
    (microsoft.public.vb.general.discussion)
  • Re: Hex function problem
    ... Function UnsignedDec2Hex(ByVal Value As Variant) As String ... Dim TwoToThe32 As Variant ... Function Dec2Hex(ByVal DecimalIn As Variant) As Variant ...
    (microsoft.public.vb.general.discussion)
  • Re: Hex to Dec and back
    ... > If you'll try Hexyou'll get overflow. ... Function Dec2Hex(ByVal DecimalIn As Variant) As String ... Dim BinaryString As String ...
    (microsoft.public.vb.general.discussion)

Loading