I would like to know how to convert a number to binary with lua.
Anybody have any idea how we do it?
convert a number to binary with lua ?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: convert a number to binary with lua ?
Integers or any number?
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: convert a number to binary with lua ?
Also, if we're talking about negatives as well, what representation would you want for those? the "standard" 2-s complement? Others are also possible.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: convert a number to binary with lua ?
"Integers or any number?"
both
"Also, if we're talking about negatives as well, what representation would you want for those? the "standard" 2-s complement? Others are also possible."
all
both
"Also, if we're talking about negatives as well, what representation would you want for those? the "standard" 2-s complement? Others are also possible."
all
Re: convert a number to binary with lua ?
Um... so you want a 2 functions; one that converts any integer to binary, and another one that does the same with floating point numbers? And you want the signed numbers to be converted to every possible representation?
Is IEEE 754 okay, or do you require the floating point numbers in every possible representation too?
Is IEEE 754 okay, or do you require the floating point numbers in every possible representation too?
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: convert a number to binary with lua ?
Well, you could use the FFI and cast lua numbers to C data types, and write those out as strings; i think that might work.
An union with members being a 32bit signed integer and a 64bit double could also be more versatile... haven't tested this for downsides though, but i remember reading something about this...
Without the FFI, it's kind of complicated, and slow, although technically they are binary already, they are doubles. If you want to output strings of 0s and 1s, that's again different.
An union with members being a 32bit signed integer and a 64bit double could also be more versatile... haven't tested this for downsides though, but i remember reading something about this...
Without the FFI, it's kind of complicated, and slow, although technically they are binary already, they are doubles. If you want to output strings of 0s and 1s, that's again different.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: convert a number to binary with lua ?
I'm sorry if I don't ask the right questions, I'm actually a big noob in programming and I'm just getting started.
I was just trying to find out how to code a function that converted an entire number into binary, but I was curious about other solutions.
for the rest, honestly I don't know FFI or IEEE 754.
I was just trying to find out how to code a function that converted an entire number into binary, but I was curious about other solutions.
for the rest, honestly I don't know FFI or IEEE 754.
Re: convert a number to binary with lua ?
As far as integers go i asked a similar question a while back, wound up making this thing which includes function for to/from binary.
viewtopic.php?f=5&t=83752
viewtopic.php?f=5&t=83752
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: convert a number to binary with lua ?
The question still remains vague as hell though; different methods are sufficient only for different end-goals:
- To show values in the binary numerical system from a specific format (like "integers", or IEEE floats/doubles, or even characters based on any encoding)
- To write out values in the most compact of ways to either files or memory
I'm guessing we could help more if you actually told us what you want to do / use this for; keep in mind, all values are, in a technical sense, binary, at all times, they are just being interpreted differently; your computer only ever uses 0s and 1s, it's just abstracted away from you.
- To show values in the binary numerical system from a specific format (like "integers", or IEEE floats/doubles, or even characters based on any encoding)
- To write out values in the most compact of ways to either files or memory
I'm guessing we could help more if you actually told us what you want to do / use this for; keep in mind, all values are, in a technical sense, binary, at all times, they are just being interpreted differently; your computer only ever uses 0s and 1s, it's just abstracted away from you.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: convert a number to binary with lua ?
I'm just trying to display the conversion of my RVBA values to binary. for example 255 to 11111111.
Who is online
Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 9 guests