Link to home
Start Free TrialLog in
Avatar of dds110
dds110

asked on

Opening Binary Files

I want to open files that are stored in ascii code (binary),and write the ascii code to a new file in text format(so that it can be read by humans).

Any help is greatly appreciated.
Avatar of Evlich
Evlich

Binary is kinda weird, but here is something. It si comprised of 8 bits that are boolean. They appear in powers of 2:
1         1      1       1      1      1      1     1
sign bit  64     32      16     8      4      2     1

In order to do it, you would have to read 8 bits and then add up the values of each bit. Then you output the character that corresponds to that ASCII value.
                                       ~Evlich
not sure how you want to format the output file but this shows how to do it (one output file in ascii and one in hexadecimal).
I have separated each value with a space and filled leading zeros (i think it makes it more "readable")

Dim fno As Integer, ano As Integer, hno As Integer, i As Integer
Dim inBuff As String
Dim aBuff As String, hBuff As String, hChar As String

fno = FreeFile
Open "c:\test.csv" For Binary As #fno
ano = FreeFile
Open "c:\ascii.txt" For Output As #ano
hno = FreeFile
Open "c:\hex.txt" For Output As #hno

Do Until EOF(fno)
    inBuff = String(32, " ") 'we'll do it 32 bytes at a time
    Get #fno, , inBuff
    For i = 1 To Len(inBuff)
        aBuff = aBuff & Format(Asc(Mid(inBuff, i, 1)), "000") & " "
        hChar = Hex(Asc(Mid(inBuff, i, 1)))
        If Len(hChar) = 1 Then hChar = "0" & hChar         'leading 0's for hex
        hBuff = hBuff & hChar & " "
    Next i
    Print #ano, aBuff
    Print #hno, hBuff
    aBuff = ""
    hBuff = ""
Loop
Close fno
Close ano
Close hno

===========
hope this helps

Sombell
Avatar of dds110

ASKER

Perhaps I was unclear in my request, so I'll try again.  The files I wish to open are *.dat files. For instance, I want to convert this:

???           IP?? ! ? ??v ? ??}?< >,5c?  ??a?} d ???6 vH??? ( ??`EB  <?x < 2w)Za 6 ????? ? ???{b ? ? #?~  .?!Vd d mP?/$ ! 4}x??  W?Q]  ?3?[?  ?????yU=4  ?&?`X          ?W?b ?  ?k?\ E ? 1?k P :12??  ??7 d A ?[??[ } ???kk P l?k  \??sP x ?k??  ?x??A A 7+|E  |?^)d ? ??-?  ???*  ?V/s?  Y ??
  Y?R?; ??|Rb ? ???,  ?W?,d K /?CH  5??      K 2 :+>^!
 esF2T  y?/Y? / ??DS ??h?? , ??r? ???(l  ??F|    ?y?K R ?w?)5  K?
?  ?????  ?????  ?0B?  Z6)?Z ? ????? ? ?=?ue   KQ??  ?`??B ` ????? ! ;6,?g ?pu?< "42?V  T???? ! V??x d ??_?s  K???? ! ??roI  ??'[  ??EqB d Sn?? 2 ??'??< ?W??   ?S?*O x ?7;?i  #q?%a "         ????e ?:? ? ? ?7M:  q???  g???  ??/?  0 ?QSpA , ?y=?? ?         f???Q          ????    ?"??  ??<      '
 FS?hr>  ???  0-?? ! ???C? ?f$|@? b#Q?K 2 ?)??K < 8?P_? yw?V          G???C  p>?1d \ V?@  w??6 - "]('  Mv???  ??j  ?qND? ? ???c?<         ????< ???? + ??%W  ?t?? ??&?d | ??5=H  {?:x?< ??
 j ??zM   ?JL?U  ??,d ? f7?MK 2 ?a*?? a'? Z ? $@J?  Q?? A???b ? ???i} ' s???  ?0??  j?8?  q ?$
 
         ?d?A   V?F?3  ?;/  ????x < 6c?M  >B?<?  ?d?? < ?Q??  $6a?? ! ?z??? K Y?x)?   ??B?  ?m??C d ?o?/ n?jK+ 2 ??U?          ;\?6  ??;  ? ?W- - ?*Y??  7?_?B d ???F@? t??? F ??l?d K _F]\ ? ?}? 
????<         ?O?lo  ???PP P q?9?e  ??Y5          ?^U?K ~ ????  a?d3?  i?D?P          ???  3??>?  ???  ?~?d  ?H?W  ???K 2 ?h?? ! j9??,  ?????< ?9-      C d ]Nj;  =)??P ' )?? 9 ?w      6K 2 s?|?I  '%,  N},s  X??-N  T??V ? ???@? ?0^?t    ????
 ???8n n ?
QH?  /r!?s  >?8kR ! ???S? ? K??x < p?F# ?G?      ?  ?^m ? Y ryd y a??? ! +?hH?  o??<?~ ??Km?# ?Z?k? ??G?x < 2???C d ??]7?  E#bA  ~???A ` ??J\? z?<o&a(Su1 1 ????P <         B???P K         ??o  h?aNx < @`Na- - \?J?< /??3L2 ???  ??(?d s |?P?? < Q?R{?                 ?+9?d M Y????  ?      ?v   ?Qa??N??d  ??? h ?         .?c?? 2 ??AeY " EX?sd  ??
? K *SA   ????          B4??K 2 H?K?K 2 ??? ?^?*d y ?t??? 5d??@? j??M h ??      t  ?????  ?v}Z?v ???? d ?{??s  ???&  ~PS?-  s?i      J  %| f  ???[  !?a?0  ?q?C d Uz??? 6D?d  2???G ?P5??  ?jbK 2 ????
 y?l8  (??? < ??E  ?Ma6Z ? ??l` x ??}  ?p Xf ! ???d  ?.?`@ # ??T  ??L$k $ ?8.?  CY?lK ; ??? | s?=7?PFWrwc) F???? \ ? ??  &e2@K 2                 ?A??  ????L2 ?l?  C???? ? ?a?zd  =???A  %9?0 v
   ?L?~?   ?ES? f         ???H          I{?? ????p 7 L???< f6]??< ??{?>  ?Mb  ????I
 n#hR  +?<?? ( E???@ P ???   ????b ? 7???  P???D d ????r d l
?}v? U???  t??7? ,?X  ?H? ? L f?$IV  ?i?N??e???L  ?I?C ` Q? BK _ h???P ? ?uY  |??5 8 ??r?b ? 6??7m  w?,*? & c???? "       N??d C {V
 ??&  N?g?  $T??y  ??gr  ?W??  ?,A ) ?N[5  Q??&P & tj}?? . ?????  r???( ( ??G?? w ??$- - _,??} d L?  "???          ????/ fz??  ??U K @ A*`??  ???e@ 0 ??G(   D3bd C ?      y? " :??m S         iom8  ???;d  ~??9  B???Y  /?x?  ????A ` ???  U<L?K ; x?i?x  2?C+?   ?f??W  D??d  x`?{?  ???@  ?????  ?z2??( ?n;??  ???=? " ????? ? ???i} } ??I?  ???! ???Bi - ?N??  ?I?7?< ? 'c  8???  ?????  .X?w? <         SD??  ?s Z/ ?d ?  0l??Z  ???TN S         ??! R
c??  )?^?? T ?
tvM < ????D         K}H?  HtR5O x ??  #??d  ?~iYg ?}??6 T l??j  ??%K @ ??$?? & ??94? n ??2  ???MR  ??? ?< ????n F #?
  s?
      +??? ?? 2  ??  ?O?   ?8p?  L???@  ????} ?O? ! ?x?:@? ?
  ??=\d  ^Xl?u &  ?"?; ?x7?? ? ?9?4?  ?_?d ? ?m??e  K"??  j?iCP P ???#?8 ???J!L ??E  ?Q???
X3?e         ?z?E  'D??? d ??J? V C??b
 v{???  ?x?} ? ???h  }Dn?  ???? ?av+  ????  g?b2  hG??Z ? ?{
h  g?M?  a2}?? 2 ?/?  h??ZQ
 ??      ?  ?~??n?X??? 2 ????< g??} } ?Z??  ?hW 1 ?n?z??A &?B d ??  ??3  ?IZ  ???K 2 ?Qa?  c?k?< ????- - 3?g??< ?D?7 " ?_??? h ????? 2 D? ?
 
 n???w ?\???# ?t!?n  ?*??? -1??l  ??B?u + ???? ?o?C _l.O  n??? W???]                E?2 2 ?0??? \ ??[+  ?? ? L?B?    s??Z C P|
V  ???B? ? ?e?RZ ~ q?!3  w4-?? % d?MA(  ?         %Y??G? I,?? 2         ????g  ?-K 2 ????c  ?9C?x S
?5yF :
??]  ?
n?#         ??|?I  H~?x - ?<??p ( >y?? @  'D?x < ????? ] ??Eg  ;I??V  ????d ? ??V?  ? Nx  ?U?~X??n??V ? :
?   ?9??  ?DP?} d ?g ,  ??+( d?\?? ! ?)???D ??9?l P ?B??@ @ ??d? < ?;??A   ??3?@? AE??M
         ?q&Pn * ??      ? n  co)H   ??8? e w??V  jR?Y? ? M$
yK < K#??R * ??G?? / ?,!?@? ??9?? . 'EF  I?oOd ?
?tBx < R?*??< ,?&?? ?M??< 9?4?  ??w?X gR?& ??*#
 =n
}  ?$-?  ?
?_P  /??.      ? k??5x c ?;?%  ?*,? K ???E
 
 ???? z ??? ??W?d ? $lK 2 ??
 
 Z z? !         P] (? d ?Y?x          ???  ?Ki?Z ? ??:?< ?b??< ?M\?              I?ud ? ??B} W???  .???Z  ?%?&  d??g? 2 ?q??}  ?????  ???yK ? ?b?K 2 \q??d ? ??\?  t?em            _0?}x  ?!z?C d O5??? ! g???K , #??D? x ??J?? $ +4?(;  v??W?   6Z? d  ??@?  [>?k ? ????? $ ????? ? >=?W  r JER  ???-d ? ??f  >[?<  q?0E%, l#?)j ? ???? K ?-?3a   ?*??? $ ????? !  q??
 p??W2                  ??o?e ? ?a?v?< ?Dtd d eN?K k F?j?x  ????v ?)??2 2 ?F;`  ??* ]???? 2 h??  ?m;? ? ?Z?eD d a?eqb ? ???e? $ ?He?d > ?Q+?5  q???C  ?.??r  w???| / ?l?I # ??-?? 
??=V  ???? ???|  ????  ??E  ?m?4?< w?;?  We? #         ?y??>3??/k k ?%??R] ??G? / ???      ? !         +Zp?< ????Z ? *?8?  c?? x O D?4&   Vf??K v ???? q ????u u ?,??  |??f  ???
P  ed?/"  ??n?P < ??Qd ?         ???!A ? C{F?X  ????? < ??      
 
 ???im ? H???  ????H a ??B ` ????] x         ?g??K @ ?V?je " J%?  ??+  ???Bd ? ?~fH(  w?X?t  ??.d  M ?? ? ?>?? 7???'          T#?"_ ( ??@?@ `
z?   ????5 ???]8  ??`?!  \W??  ???Q  !0??? ? h-*?? ? ?? R  (?O?K ; #l??l  4$???   ??SP P ??  1?rH  ??v1n  T?<d ? ???? < ?A?E? ?
?)?R !         JN??? ??i  ???M  ??t?? ? ??K?J  q?# 0
??( / ??Z?*  ?y?.? ????# &         X???? ?'6H?  ??b?  ????x        ????< ~I.?.  .V
??  ?_ ? l ?U??? ??D?x < ?yj  0??$n x a???  ?~z?  &???? c Bw??Z '         ?t?  ^lJ$x Z         q|?]Z ?G$?U  ??&?  ????          ?R???< ???A d 2|e   -:??  ?_:P  ?-?
  t???5  ~P?I  ??|d  4?
??  4R?y  K?[j  5??A  ??? =?}@  1d??          ?` &?  ?:???  e?{?>          x?`_?  ?*?
d | ?H?d ? ?x??          ???-?          ????? 2 9?*0          /??`? ! ?FT&  ???7  ??}q? *?}ln  Y\;?? 2 ????? ? ]?'?  yqR?  [G?*i 2
?? ?t?g' ?+ ?s          ??? ?  AD?   ????2 2 ?      ??? d }"?? v ??vF  ??      B j??-? Z???X a??O  Rk?    ?R ?? d ?#???< ????? ( #?hJ?. ???Dm L n]\2       
 ???   m!?  ?9$w? ? ?k?j??jR??N  ?!8?  ??w?d C ?~?}  [ZgN(
 ????d s ???%,         ?Wk o ???  B@?W3 ) 5sG?  C??JF : S+j?3  ?1~?  ???j  ?.,?C B ?,"@?  Gv?          n???X ?YB?? ! I??H ) ?)?V x ?s)%+ F???T } ?b??? d ???U  p??K  ?L?Q ` ??%Kb ? ??PW? ? &??a ` S?[;  ???? ! ?????? L???x  /2?S} } ????F / tz?  $???b ? ?|z?  Ds?R # 3H??  ?o8?  ????} d [??          ?9  ??*???d???< ??l X  Z????/ W?*?d | ??"i        ????s - '?Z'??M?{B EB6P  ;??fZ ? ???d  ?H\?  6?:+S  bi?  ??Dn  ???y  ??=?  sT?d  Z???  X??V  ,?=} d YM?p ( ?~J?} } ? (} d ???eP P ??f # @`??  Q??.  ???: $ Aq?H  ?}?n n q??oK 2 ????I  nAa#@? N???s V ?C??m  <?Ku?   p?o?R\ ??U   9 rd ? ??O?$          ???]n  5&?`?  <?d C ??? @  ?J?\? y         ??P8?  ? ?qwG ??c*"  Ouv??  ??}? 0?1?k k ?G@K 2 <??  ?7?{  ?p          ?\??< ????  %9??K U w???a  ????? ?X{?  3??Z ? _g?C?   ?71??  @`?k,? ????  T?=?V ??YC c <)`?b         d'      d ? ?L?R?< '?r(       v?? < ?v!@? ?O?b? ? ?????w ?v??-  ??*:? 2  ?.fN? ?xr?  :;??-   ?~.d < ~I{? $ ????I d ?Dv"  ?:???  tyo? ! ?<??"   |X1?y  ??WZ  ,????  ??#?< < ?2?  %? B ` ?d??0 ???.  ?%??b ? ?X?? ! ???m S ??D?d b ???XVM4   P??~? 2 ?C??% ! Cr+?  ?5?B@? ????? ?d??  0?      >[ [ ??3m ? ??y? ?u??
 J?y ?{b??  P@?JR x ????   B?HK @ E?H?? 7 ?-??X ??? < ???a} d ;Z??2   ?_?
 ?f?? ? ? ?)?  v`C
P  ??Y?  ?8l?K @
f!@? ????X > ?Va~?  }??!?        L27 ( ??
*  ??E@d K ??Y  ??H ???a ? %??r0 $ V???7  ???u   ???  0?)5~        <?a? 
#?X ?$v?  i4??          N???N x C+??V  ?Q?T  a??Z ? ?ad?? ?B??I  0??_  ?l?? L ?;?T x ZF      '? x 1%8?K < ?ZcFW  ??O??  ??X??< ??zh( ??ZI  ?:4@ 0 ?m0?b ? ????A d ???d K ?y??d C       =?? ? ??O  9??(
 ??(?W  ={A I  ??M?*  ?m?+?  5O?w  0??Zs P ???9  ?L??b j ??SU #  1,G  v5??? ! A???S ? +q)^d ? ??<d < ?C?   ?*?}C ` ?B?          ???? T F2?   ??mJY *         ?? ?d  !o??{t l- - ?`??_
 d?az  !???  ?nq   Z??m ? 5??] w :/?Z ? -f ]P K ?(#d | .?A 8 3??? ( "?G? m\?X p??b ? ?yz?? d /??  Goxd ? ????? ! ????  ?<_?
 ?H??? 
?K??  ?>C ` ??`?? F ??mc? R         ???t? 7 ??U}  _???n n ??
?d } ????? ^'??^?>R?^Rf <
?z? d s?<?  ????P K ?M?? ! ?
??? ( <
HuB ?0?e  >???? 2 ([qVs S ;"?>n ? ?x?Jm Kqn?
 ??n?B ` ??9?  ?p?4R] i???g ????  ????? P ??0<d  ???? ! ~g ? Bk??   ?
? f?L?d ? 6?d?hc?\??  O??%d  ??\5  ??(?d  HL??R9 ??8?? :????  B?_;  ??A3C ` ?*6?? B !??I  J?X? / ???n} O ?>5Y  ?~?l P t? ? ! b??[? ? ?f??  cx?x < ?M?x < ???? h ??2?   ???? ? T??Qx ?????K ( x9?y{ ; ?w?i # ??? x S {<?%L * ????X????wK 2 3?w?   ??R?A @?]W@ `        ??B ` p??  ????B ` ????p ( ??b??. ??UH  /???? ? /8?i ^ m)?oT } X^?  '?  ????a " ??Y??<         N??@ 0 ???%? F ???p 7 ?{??x < ??l?d          \>% ?  +Oq~D  ???w N ??HLb ? ??p??  ???? d ????d K ?U)? ? ??N?n  T?@?  ??*w  g?? I         ??h?  u?6?b ??SV  ????t  ???D         .,??? ??T?:  (S??tK ?W?  ?U;r? ?]?? d F??9? 9 9??b ? ??x < ?&??? @ ?6?\  1Md C ?f|Pn?>?i? ?         ??r? x O.\?? # ?!??r ?I?u c?GK & f?I?? ?[?? ? qe@?2  ??
?? ! ??Y? ? ?*? B?      l?< ??BIxb?d?{  V?w  2??$  ?'??h U ?1??? ! F??P P ??zI  ?j^T? ?3AB ` ??^?
 
 ??-`W  ?bf?  <ux?        ???  ?_??  ??MP  T??Z  F??2? 2 ?O??Z # Bom        ????  <H& ?  8??  ??f?>  ?qLG  (???  zK??
 
 ????  SB8W?  ??????oGW(  ??g??A ?\P d # ^???          >??  K???b ? ?|??Y I ?i???< X??    ?px?  ?\IS  -?W?          ??S?9 U 05#e            u_??? ? ??E3P K         ?M?gC          e??  ???R  ????  ,???? ? x???  ??P P ?2??O x $JM  L?td  ???u   ?h?O? E         ?!?? 2 ??e?  ?@]?< # ??.?1 K ?^??? d nvz? 9 L?Nz < ???P  ?z??  L??ZD&  Q?S x ?h?a? ???t  >?k o ?[??? ??P? 4 ? ?QK @ ?&?
  ?      p > ?HI?   ?K;?? < l7??  \?7??  ?A?< a         ?iJ?? _ ?3?}         I??K ; ??3WP K ???P? ?[?B  N????. ?&??b  ?      ??( , &^!?(  \??? !         ??)0          ?,??? 2 ??iU? ? Z?  ??2A@? ???  ?[?C( ( l?r?d ?8
R ! k?i?@ d ?!S~&  ?r
Jm ? ?q??A   ?>?e ! ?S/D  1?? $ g??R} } ??;?<  ??HA 8 ?gs?N x G???N  ?      ?d } ???
 ?I??  ?P5d < ???< ??8  ?+ K h ????  ?F?  ????U  t?
I} } ]???N x k??
 ?&???  ,???d  ????  ?p??? GC?  ?Q?x  ?y??  t? @? ????? ! ???????????\?N
 ??q? < ?E;?  8???d ?s???< Nn??          ??J?? h ?????          ?l?[  ????  5??              i??;G < ???+?  M??*   ??c0  x???  ???? WG(?  ?????
         ???TRf b7yrd { ?\? Z ??c                 4c5? ! ??W=  Lo?x l D??d  Tg???  ,G?AP P ????? 1 ?OXEd + 0n??P K ? ???  ??N*@? t7k ~ \ ;?>?
  ?w      ? ! ??g?  ????? ! et?k k ??h?  O`FR ! 8??H  ?s              ????K d =jR?  ???F   ?BmR              ???  z]      ?P E ???W  ?4?{  ??-?~ \ ???y  ?E??? ? ??8l` ? ???r ???d < \?n?  ?B?xb??I?  L5v?d < ???(  ??K??  ???q  *??sl  :??SQ  ??0?x/????          ?? P K ?a?f? ? *XI?d 2 l???j  RX  ??T ? ] ???>H d d?Fa? ' v?r  _????D -??d  ??x?x x ???L? G dQ?  ???? ?
??? $ ??_?? c ocE^  G??!P K ?AI?? ! ??]x  ??#?  R]?y?  Wk?&? ?\?  ???i? h 7???  ???)  ?4o??P 8;??a   ??SK  =??*? ) ???  ?/??Z
 ?S??  ?S?          ??c?@ # ???
? ? ???=  )?d  b=?$d K -?$
 j ??? 9         :??? ! ?p??P P ; w  [>'r o ????  ???d C .?b?P K ??b?I
 i9??? !
9?.   Q???d 2 _A?>? 9 hd ?  ??zi? K i??V?< ? fA Z ?o?5y  \??          ????? ! :R??? P O8b?  5?jO N ??n?x  ????^ ? ?1J  !??W%+ ???6g  BI??P K ?<??} d ????X? &C??  ??m~ ? ??8d  ??A?P P |vu?d ~ ?{8?  ?8?  ?V@? ! ?{???  f??(I  ?O ? < C?KI@ 0 4??'?  g??a?7 ?L??- - ?cl        Y?v? ? @?X]   ???,? ??c? $ ???a  ?)??j  ???/  LZu?V x ?V?X  h??b ? }EH d ????  ????  5??k k v1?8x < R??G? y                 ?iR5          ?]R? 
?M?A  LI??  ??~? ? ????  ??v?  ???}  ?????
??` ? ??G?  ???  ???^%+ 2L?  G???h U ??q?F E ???Z? c?G?  ??";? =         ????? L ?????   {?r?< ????5  h?f3  ?      Q?Z ? 2?z?K 2 ???C  '}?K2
 F??  $ ???)?  jI??- - ???$p 7 ?@??  2? ?P P Qv? K ????C d H??? G               ???< /??=?< d?o??  {?
?d!         m???  i?#?  3??IGa`f?} " V*??  G[?`  ! a3[@B d ??&?< ?_??X??jF?} O ??7          ?a?d  ?
?kg  }-??? w ?7?
? I         ? ?  ?4
?< <?)P x ???'p # )?k?   ?>3B?< ???#9  ?!??B  ?O?nK ; Q???G  ??~>?  ????x < ?=?Jr  v?Z]  ???L& ???? ?P_5?  ?? ? ` ?????  ???? {X??? d c?>          ???3K ; ??
??? ?d  \???R ! (a???  ???&d  ?U??
 
 ???Tj  ????
 N???P P jQ?7  ?1?&K 2 ????   ??

And save it as a human readable text file.  Thanks for the quick responses.

 Any other suggestions?

ASKER CERTIFIED SOLUTION
Avatar of sombell
sombell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sombell is right. Technically speaking that file is human readable form, meaning those are the characters that we can use and understand... but you will need to either decrypt the file or find out how it was structerd
Yeah....