Qbasicnews.com
January 26, 2021, 09:38:34 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
:
Back to Qbasicnews.com
|
QB Online Help
|
FAQ
|
Chat
|
All Basic Code
|
QB Knowledge Base
Home
Help
Search
Login
Register
Qbasicnews.com
>
Qbasic "like" compilers/interpreters
>
FB Discussion & Programming Help
>
Is this possible? Brute force conversion
Pages: [
1
]
« previous
next »
Print
Author
Topic: Is this possible? Brute force conversion (Read 9071 times)
wallace
Wandering Guru
Posts: 368
Is this possible? Brute force conversion
«
on:
January 20, 2007, 01:44:13 PM »
Cast doesn't do what I want it to do. I have a single precision float that I want to store in an array of integers. They are both 32 bits so it's possible. I want a way to convert 12.3423 into an integer and then back to 12.3423.
The binary representation of 12.3423 is 01000001010001010111101000010000 (IEEE 754) which is 1,095,072,272 in integer format.
Doing int = cast(single, sing) gives me a value of 12 for int.
Logged
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
stylin
Ancient QBer
Posts: 445
Is this possible? Brute force conversion
«
Reply #1 on:
January 21, 2007, 01:03:06 AM »
This seems to work:
dim f as single = 12.3423
dim i as integer = *cast(integer ptr, @f)
print *cast(single ptr, @i) ' prints 12.3423
edit: wee, 420 posts..
Logged
stylin:
TheAdventMaster
Ancient Guru
Posts: 671
Is this possible? Brute force conversion
«
Reply #2 on:
January 21, 2007, 04:14:13 AM »
Quote from: "stylin"
edit: wee, 420 posts..
grats.
Logged
wallace
Wandering Guru
Posts: 368
Is this possible? Brute force conversion
«
Reply #3 on:
January 21, 2007, 04:59:00 AM »
i may be super drunk , but that is just transfering pointers, whic works fine, i actually awnaty to store that data in the array and not fjust a pointer to it,; is ther aa way to do that>
Logged
f you play a Microsoft CD backwards you can hear demonic voices. The scary part is that if you play it forwards it installs Windows.
stylin
Ancient QBer
Posts: 445
Is this possible? Brute force conversion
«
Reply #4 on:
January 21, 2007, 05:10:51 AM »
It works with arrays, too:
dim f as single = 12.3423
dim array(0) as integer = { *cast(integer ptr, @f) }
print *cast(single ptr, @array(0)) ' prints 12.3423
The reinterpretation of the raw data is what you want. It seems a direct cast from single to integer converts the value - that is, it truncates the decimal; C and C++ do the same thing. Casting the pointer type - the address of the data - from float pointer to integer pointer does not convert the value, it just reinterprets the floating point raw data as something else - the value does not change.
Logged
stylin:
D.slert
New Member
Posts: 7
Is this possible Brute force conversion
«
Reply #5 on:
October 23, 2009, 11:28:33 AM »
Is it even possible to have a NIC Card in the back of your PC and have a crossover cable running from the back of your xbox to the back of my pc and be able to ftp into evox. Or are my IPs just messed up.
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Forum has moved
-----------------------------
=> Forum has moved
-----------------------------
QbasicNews.Com
-----------------------------
=> QB/FB News
=> Site/Forum Issues
=> Challenges
-----------------------------
QBasic
-----------------------------
=> QB Discussion & Programming Help
=> QB Projects
-----------------------------
Qbasic "like" compilers/interpreters
-----------------------------
=> General QB "like"
=> QB64
=> FB Discussion & Programming Help
===> FB Projects
===> FB Documentation
-----------------------------
General
-----------------------------
=> General/Misc
===> Art & Music
===> General Programming
Loading...