Command & Conquer Communications Center

keeping the classics alive!

Author Topic: Convert 2 bytes to a double?  (Read 812 times)

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Convert 2 bytes to a double?
« on: February 12, 2011, 02:56:57 AM »
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.

Quote
//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
« Last Edit: February 12, 2011, 04:18:40 AM by ShadowDog »
Quote from: Nyerguds
Get that Starcrap outta my C&C :P

Offline Nyerguds

  • C&C1 H4x0r
  • Global Moderator
  • *
  • Posts: 3290
  • Green Forum Alien
    • View Profile
    • C&C95 Project 1.06
Re: Convert 2 bytes to a double?
« Reply #1 on: February 12, 2011, 07:22:27 PM »
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.
« Last Edit: February 12, 2011, 07:31:06 PM by Nyerguds »

Offline ShadowDog

  • Grenadier
  • *****
  • Posts: 61
    • View Profile
Re: Convert 2 bytes to a double?
« Reply #2 on: February 15, 2011, 11:22:37 AM »
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.
Quote from: Nyerguds
Get that Starcrap outta my C&C :P