Transform hexadecimal value into a string? (FMod)

BlitzMax Forums/BlitzMax Programming/Transform hexadecimal value into a string? (FMod)

Grisu(Posted 2009) [#1]
Hello again!

I have a version int which I need to transform into a version string number.

"The version int is a 32bit hexadecimal value formated as 16:8:8, with the upper 16bits being the major version, the middle 8bits being the minor version and the bottom 8bits being the development version. For example a value of 00040106h is equal to 4.01.06."

Can someone explain to me what this means?
Is such tansformation possible with bmx?

Thanks!
Grisu


GfK(Posted 2009) [#2]
Taking 00040106 as an example in a var called version:string:

Major version: 0004 (Left(version,4))
Minor version: 01 (Mid(version,5,2))
Dev version: 06 (Right(version,2))

Isn't it as simple as that?

[edit]You could get all clever and achieve the same with some bit-shifting if you didn't want to involve strings, but I'm not sure its really necessary in this case?


Grisu(Posted 2009) [#3]
Thanks GfK.

I currently only have an integer value, so I can't read it that easily.

Integer value = "270342"
Should become: "4.26.00"

Feel like a newbie... :/


GfK(Posted 2009) [#4]
Eh?

Integer value = "270342"
Should become: "4.26.00"


I don't get 4.26.00 from that - I get 4.32.6?

version:Int = 270342

Major:Int = (version Shr 16) & $FFFF
Minor:Int = (version Shr 8) & $FF
Dev:Int = version & $FF

Print "version: " + major + ":" + minor + ":" + dev


Either I'm missing something here, or your translation (above) is wrong?


Grisu(Posted 2009) [#5]
Guess, it was my mistake.

I think Fmod is cheating on me...

INT value: 270342 -> FMod DLL: 4.20.06
-> Results in: 4.32.6

INT value: 270375 -> FMod DLL: 4.20.27
-> Results in: 4.32.39


jsp(Posted 2009) [#6]
I don't think Fmod is cheating, it just cuts the bits different
270375 =
100 0010 0000 0010 0111
4 . 2 . 0 . 2 . 7

it uses 4 bits (nibble) instead of 8 bits (byte) in a group


Grisu(Posted 2009) [#7]
Sounds logical. But I'm not sure how to code that. Can you give an example code?


Brucey(Posted 2009) [#8]
Local version:Int = 270342

While version

	Print version & $F
	
	version :Shr 4

Wend



Grisu(Posted 2009) [#9]
Thanks a lot everyone! Issue solved.

...and the fmod manual is false :(