Jump to content
  • 0

Convert 2 bytes to a double?


ShadowDog

Question

I'm trying to Dune 2000 maps, but unlike TD's .bin files, it's 2 doubles for every tile. Unfortunately, you can't store a double in a byte, so it's 4 bytes. I grew up modding CnC, so when I figured out how storing stuff worked, I went with .ini files over any sort of binary format. I think I have to use some sort of "bitwise operator". It's stored in Little Endian, BTW. Would I do something along the lines of "byte2 & byte1"? Thanks in advance.

 

P.S. On the top bar, "Hosted Sites" is listed twice.

 

EDIT: I got it working, but I still want to know how you're supposed to do this in a non-interpreted langauge.

 

//fileid = file_bin_open("test1.bin",0)

//Remember, file is stored Little-Endian style.

//29 02

byte2 = $02 //file_bin_read_byte(fileid)

byte1 = $29 //file_bin_read_byte(fileid)

 

concatenated_bytes = dec2hex(byte2)+dec2hex(byte1)

 

show_message(concatenated_bytes)

 

execute_string("ccn_real = $"+concatenated_bytes)

 

show_message(string(ccn_real))

//Should give us $0229 (Decimal: 553)

 

Based off of the specs here: http://code.google.com/p/dune2000plusone/wiki/mapFileSpec

hostedsitesarehosted.png.b2e074f4ae9f93927ecbf99a990e016c.png

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

hibyte*0x100 + lowbyte

Just that should do the trick... which is Hibyte and which is lowbyte depends if it's big-endian or little-endian of course. And that's 100 in hexadecimal, of course.

 

It would help to specify which programming language you're talking about though. Different languages have different ways of expressing hexadecimal numbers.

Link to comment
Share on other sites

  • 0

I'm using Game Maker, but I wanted to know how I'd do that in some sort of C/++/#/Java-ish language. That'll definitely work much faster than converting 2 numbers to strings, concatenating them, and abusing the fact that Game Maker is an interpreted language.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...