• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
greenpig83

Binary to Integer (Read hex binary file)

6 posts in this topic

I'm trying to read an unknown type file (a save game file, I change the value and then see the file in Hex editor) !

And i want to read the integer values. I know where it is ! but the hex value is quite strange! I use Decimal here for easy understanding!

 

(byte-byte -> integer )
           //128,63 -> 1           128 =  10000000   63=00111111
            //0, 64 -> 2(10)            00000000-0100000064=    01000000
            //64-64 -> 3(11)            01000000-01000000
            //128-64 -> 4(100)          10000000-01000000
            //160-64 -> 5(101)      160=10100000-01000000
            //192-64 -> 6(110)      192=11000000-01000000
            //224-64 -> 7(111)          11100000-01000000
            //0-65 -> 8 (1000)          00000000-01000001
            //16-65 -> 9(1001)          00010000-01000001   
            //32-65 ->10(1010)          00100000-01000001
            //48-65 ->11(1011)          00110000-01000001   
            //64-65 ->12(1100)          01000000-01000001
            //80-65 ->13(1101)          01010000-01000001
            //96-65 ->14(1110)          01100000-01000001   
            //112-65 ->15(1111)         01110000-01000001
            //128-65 ->16(10000)        10000000-01000001
 
            //136-65 ->17(10001)        10001000-01000001   
            //144-65 ->18(10010)        10010000-01000001
            //152-65 ->19(10011)        10011000-01000001
 
            //160-65 ->20(10100)        10100000-01000001   
            //168-65 ->21(10101)        10101000-01000001
            //176-65 ->22(10110)        10110000-01000001
 
            //32-66 ->40(101000)        00100000-01000010
 
            //48,64,80
 
            //160-66 ->80(1010000)      10100000-01000010   
            //162-66 ->81(1010001)      10100010-01000010
            //164-66 ->82(1010010)      10100100-01000010
 
 
(bigger values, int,int,int -> byte-byte )
//80,81,82  -> 160-66,162-66,164-66
            //180,181,182 -> : 52-67,53-67,54-67
            //20,21,22 -> 160 ,168 , 176 -65
            //30,40,50 ->  240-65,248-65, 0-66  (3 integer -> 3 (2bytes))
 
//128-191 -> -1             10000000-10111111
            //0-192 -> -2               00000000-11000000
            //64-192 -> -3              01000000-11000000
 
The values is like above. It use 4 byte (but only 2 byte have values) . It seems that the left-most bit of 2nd byte are for Signed!
There is some rule , but i find it hard to figure out !
Thanks !
 
Edited by greenpig83
0

Share this post


Link to post
Share on other sites

Your notation is extremely cryptic and you do not explain anything - i would be amazed if anyone would be able to guess what you are talking about.

 

Anyway, just in case, this is how values are stored on your typical little-endian format:

 

(2 byte integer)

original value: 4660 -(hex)-> 0x1234 -(as bytes)-> 0x34, 0x12

original value: -4660 -(hex)-> 0xEDCC -(as bytes)-> 0xCC, 0xED

Note: 0xEDCC = 0x10000 - 0x1234

(4 byte integer)

original value: -123456789 -(hex)-> 0xF8A432EB -(as bytes)-> 0xEB, 0x32, 0xA4, 0xF8

 

edit:

If i understood your notation - looks like floating point to me. Treat it as a standard 4 byte float - see if that does the trick.

Edited by tanzanite7
1

Share this post


Link to post
Share on other sites
It's a 16-bit floating point type.

#include <cstdio>
#include <cmath>

void print_as_tinyfloat(int i) {
  int sign = (i < 0);
  int exponent = static_cast<int>(std::floor(std::log2(std::abs(i))));
  int mantissa = (i << (7 - exponent)) ^ (1 << 7);
  unsigned tinyfloat = (sign << 15) + ((exponent + 127) << 7 ) + mantissa;

  std::printf("%d -> %d %d\n", i, tinyfloat % 256, tinyfloat / 256);
}

int main() {
  for (int i=1; i<20; ++i)
    print_as_tinyfloat(i);
}
1

Share this post


Link to post
Share on other sites

Wow, never think of that. I just think inside the box that it must be integer!

I'll try and see if it's right ! Spend hours to figure a very simple thing sad.png

 

Yeah. that it ! Using C# it's more simple !

 

byte []t={0,0,32,65};
float myFloat = System.BitConverter.ToSingle(t, 0); //-> return 10
 
Because the game only let me input integer value, so I think that it's integer !
Edited by greenpig83
0

Share this post


Link to post
Share on other sites

It's a 16-bit floating point type.

Half-float does not have an 8-bit exponent tongue.png. The realization that an exponent could explain the related change in the byte pairs and the one bit crossing the byte border (due to the sign bit) was the smoking gun for me. The exponent encoding works as a fair giveaway too, but missed it at first (64 = 128 >> 1).
 

Because the game only let me input integer value, so I think that it's integer !

This has been actually very common occurrence i my savegamemucking endeavors. Even with values where having a float makes no sense - ie. the value can logically only be whole numbers (a'la unit count etc).

Edited by tanzanite7
1

Share this post


Link to post
Share on other sites
I thought for a minute that it was a strange custom 16-bit float with 8-bit exponent and 7-bit mantissa, but what's really going on is that it's a traditional 32-bit float, and the OP only gave us the 2 non-zero bytes (and I missed the comment about the two zero bytes). The other two bytes are always zero because for small integers they represent things after the point.

So just forget the code I posted. The answer is that it's a float, as tanzanite7 pointed out. Edited by Álvaro
0

Share this post


Link to post
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
Sign in to follow this  
Followers 0