Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
INT <-> Binary
#1
Does anyone have a INT to BIN and BIN to INT convertor? I thought about this, and it would be very very space efficient of a method for storing fonts (well with my method, considering my fonts use 0s and 1s without anything inbetween, including carriage returns).
earn.
Reply
#2
Search the forum, you'll find what you're looking for Wink [i wrote code recently for that]
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
except it is inefficient.

Each time, you have to divide by two. Dividing by two means that you have to divide the first digit by two, carry, second by two carry, etc. and start all over again! Insanity!

Luckily for you, you lucky dog, integer division is (should be) specialized part of your chip which gets you the answer much faster than if you had done it digit by digit.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#4
Dividing by two is replaced by SHR AX. It takes 1 cycle to execute, so it is not very slow Wink

You can also try to optimize:

DECLARE FUNCTION FastInt2Bin$ (Number&)

Code:
FUNCTION FastInt2Bin$ (Number&)
   St$ = HEX$(Number&)
   Res$ = ""
   FOR i% = 1 TO LEN(St$)
      SELECT CASE MID$(St$, i%, 1)
         CASE "0": Res$ = Res$ + "0000"
         CASE "1": Res$ = Res$ + "0001"
         CASE "2": Res$ = Res$ + "0010"
         CASE "3": Res$ = Res$ + "0011"
         CASE "4": Res$ = Res$ + "0100"
         CASE "5": Res$ = Res$ + "0101"
         CASE "6": Res$ = Res$ + "0110"
         CASE "7": Res$ = Res$ + "0111"
         CASE "8": Res$ = Res$ + "1000"
         CASE "9": Res$ = Res$ + "1001"
         CASE "A": Res$ = Res$ + "1010"
         CASE "B": Res$ = Res$ + "1011"
         CASE "C": Res$ = Res$ + "1100"
         CASE "D": Res$ = Res$ + "1101"
         CASE "E": Res$ = Res$ + "1110"
         CASE "F": Res$ = Res$ + "1111"
      END SELECT
   NEXT i%
   FastInt2Bin$ = Res$
END FUNCTION

This one doesn't make divisions Big GrinBig GrinBig Grin
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
Code:
St$ = HEX$(Number&)

Um, yeah.

....
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#6
I don't quite understand that function much well... It looks like it only does a 4 digit binary number.

Let me explain myself a little more... My fonts can contain any amount of digits ranging from 2^2 to 48^2 (obviously not all the fonts will be squared, and the numbers might be able to go a little higher. But my point is, they will be all 0s and 1s and therefore it would be a lot more efficient if I stored them as a decimal (or hex) instead of writing all the 0s and 1s out. This format won't be easy to edit though, so it will have to be a product of another file. In the end of this miniature project, I might even have a font-editor available for you all. Though, nobody likes making fonts. Shit, I only made A and B so far (only uppercase, too). Anyways, if you could get back to me now that you understand a bit more... Smile
earn.
Reply
#7
Here is an example of my program Big Grin

http://www.sephplanet.com/fontprog.zip
earn.
Reply
#8
Okay I modified that to be Hex to Bin, but now I need Bin to Hex... Anyone?
earn.
Reply
#9
It worked like a charm. Thanks guys, my font method is much improved upon. Big Grin
earn.
Reply
#10
Here is the old format that I editted in notepad:

Code:
. .05.08
00000
00000
00000
00000
00000
00000
00000
00000
.A.08.08
01111110
11111111
11000011
11000011
11111111
11000011
11000011
11000011
.B.08.08
11111110
11111111
11000011
11111110
11111110
11000011
11111111
11111110
.H.08.08
11000011
11000011
11000011
11111111
11111111
11000011
11000011
11000011
.i.04.08
0000
0000
0110
0000
0110
0110
0110
0110
.E.06.08
111111
111111
110000
111110
111110
110000
111111
111111
.v.07.08
0000000
0000000
0000000
1100011
1100011
1110111
0111110
0011100
.e.06.08
000000
000000
000000
011110
100001
111111
100000
011110
.r.06.08
000000
000000
000000
111110
110011
110000
110000
110000
.y.07.09
0000000
0000000
0000000
1100011
0110110
0011100
0011000
0110000
1100000
.o.06.08
000000
000000
000000
011110
110011
110011
110011
011110
.n.06.08
000000
000000
000000
111110
110011
110011
110011
110011
.!.05.08
01110
01110
01110
01110
00100
00000
01110
01110

Here is the newer format which the program does recognize easily...

Code:
.05.08.0000000000
A.08.08.7EFFC3C3FFC3C3C3
B.08.08.FEFFC3FEFEC3FFFE
H.08.08.C3C3C3FFFFC3C3C3
i.04.08.00606666
E.06.08.FFFC3EFB0FFF
v.07.08.0000063C7DDF1C
e.06.08.00001E87F81E
r.06.08.00003ECF0C30
y.07.09.00000636C70C30C
o.06.08.00001ECF3CDE
n.06.08.00003ECF3CF3
!.05.08.739CE201CE

You can see the difference in filesize... Imagine if the file was saved in binary! Big Grin
earn.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)