Buenas:
Este código hecho Python abajo, quiero adaptarlo a C#, sea en consola Windows Form o WPF, que haga la misma función.
import os, sys, tkFileDialog,Tkinter
root = Tkinter.Tk()
root.withdraw()
formats = [ ('Roms Super Nintendo SMC','.smc'),('Roms Super Nintendo SFC','.sfc'),('Fichier Bin','.bin'),('Roms Super Nintendo','.smc .sfc .bin') ]
input = tkFileDialog.askopenfile(parent=root,mode='rb',filetypes=formats,
title='Seleccione el archivo para intercambiar bin HI a LO como A16->A15, A17->A16...A21->A20 y A15->21')
if not input:
print "Error: no se puede abrir el archivo."
sys.exit()
output = tkFileDialog.asksaveasfile(parent=root,mode='wb',filetypes=formats,title='Crear nombre de archivo de salida.')
if not output:
print "Error: no se puede crear el archivo de salida."
sys.exit()
# Leer el archivo de entrada a una matriz de bytes.
data = bytearray(input.read())
# Calculando el tamaño de la habitación en 2 exponentes.
expsize = 0
bytesize = len(data)
while bytesize > 1:
expsize += 1
bytesize = bytesize // 2
# Iniciar una matriz de bytes vacía de tamaño adecuado.
buffer = bytearray()
for i in range(2**expsize): buffer.append(0)
# Hagamos el intercambio.
count = 0
for i in range(len(data)):
addr = (i & 0x7fff) + ((i & 0x008000) << (expsize - 16)) + ((i & 0x010000) >> 1) + ((i & 0x020000) >> 1) + ((i & 0x040000) >> 1)
+ ((i & 0x080000) >> 1) + ((i & 0x100000) >> 1) + ((i & 0x200000) >> 1)
if addr != i: count += 1
buffer[addr] = data[i]
print "Intercambiadas %s (%s) direcciones" % (count, hex(count))
# Escribir archivo de salida.
output.write(buffer)
# Cerrar archivos maneja.
input.close()
output.close()
Gracias.