D - Quick and easy request: binary literals
- QUS (3/3) Aug 06 2003 Allright - octals are pretty useless (or aren't they?), but I was always
- Sean L. Palmer (4/7) Aug 06 2003 Seconded.
- Charles Sanders (6/14) Aug 06 2003 That first zero kind of makes it hard to read though.
- Bill Cox (5/6) Aug 06 2003 Sure, make it four.
- Walter (13/20) Aug 06 2003 binary
- Ilya Minkov (14/25) Aug 06 2003 Because it's not *standard*, man! It's being avoided for portability!
- Vathix (12/37) Aug 06 2003 years
- Matthew Wilson (4/7) Aug 06 2003 What an amazing and obvious idea. I can't believe no-one's thought of it
- Burton Radons (2/10) Aug 06 2003 See Ada.
- Matthew Wilson (4/14) Aug 06 2003 Ah!
- Walter (9/20) Aug 06 2003 years
- Ilya Minkov (5/10) Aug 07 2003 Then why don't you simply forbid numbers which start with a zero? After
- Riccardo De Agostini (4/7) Aug 25 2003 This one *rocks*!
- Mike Wynn (17/35) Aug 07 2003 years
- Walter (8/16) Aug 07 2003 piece
- Sean L. Palmer (31/54) Aug 08 2003 I would use it.
- Matthew Wilson (2/5) Aug 06 2003
Allright - octals are pretty useless (or aren't they?), but I was always missing binary literals from C++. Would it break anything if we had binary literals in D? Sometimes it saves a lot of time!
Aug 06 2003
Seconded. Why not 0b01010101? Sean "QUS" <qus go2.pl> wrote in message news:bgr5h8$u9m$1 digitaldaemon.com...Allright - octals are pretty useless (or aren't they?), but I was always missing binary literals from C++. Would it break anything if we had binary literals in D? Sometimes it saves a lot of time!
Aug 06 2003
Thirded!Why not 0b01010101?That first zero kind of makes it hard to read though. Charles "Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bgrch4$157i$1 digitaldaemon.com...Seconded. Why not 0b01010101? Sean "QUS" <qus go2.pl> wrote in message news:bgr5h8$u9m$1 digitaldaemon.com...binaryAllright - octals are pretty useless (or aren't they?), but I was always missing binary literals from C++. Would it break anything if we hadliterals in D? Sometimes it saves a lot of time!
Aug 06 2003
Charles Sanders wrote:Thirded!Sure, make it four. I have to agree with Walter about the usefulness, but it seems so easy to add... Bill
Aug 06 2003
"Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bgrch4$157i$1 digitaldaemon.com...Seconded. Why not 0b01010101? Sean "QUS" <qus go2.pl> wrote in message news:bgr5h8$u9m$1 digitaldaemon.com...binaryAllright - octals are pretty useless (or aren't they?), but I was always missing binary literals from C++. Would it break anything if we hadThat exact syntax has been supported by Digital Mars C and C++ for 20 years now. It's even supported as a printf format. To my knowledge, nobody has ever used it. The truth is, it's easier to deal with bit patterns in hex. Quick, what is the value of 0b110010000001000? If you're like me, you stick a penpoint on the screen and count the 0's. So much easier to deal with 0x6408. The only time I found binary notation useful was when I was creating data for a bitmapped cursor <g>. I don't see octal used so much anymore, but a lot of legacy code used it because it mapped well onto the PDP-11 instruction set. Lots of people got used to using octal, and it carried forward into hex computers.literals in D? Sometimes it saves a lot of time!
Aug 06 2003
Walter wrote:That exact syntax has been supported by Digital Mars C and C++ for 20 years now. It's even supported as a printf format. To my knowledge, nobody has ever used it.Because it's not *standard*, man! It's being avoided for portability! Why do you think people use C++? Because it's *standard*. Whatever makes it into D, shall become standard within D. And thus gradually accepted.The truth is, it's easier to deal with bit patterns in hex.Not always.Quick, what is the value of 0b110010000001000? If you're like me, you stick a penpoint on the screen and count the 0's. So much easier to deal with 0x6408. The only time I found binary notation useful was when I was creating data for a bitmapped cursor <g>.Argh. You must allow for an underscore in numbers. It shall also do readability of integers and floating-point numbers a lot of good. 0b_11111000_00011111 BTW, does this bitmask ring the bell? Well, things like that are not at all rare, and i don't want to need a bin-hex table at hand all the time!I don't see octal used so much anymore, but a lot of legacy code used it because it mapped well onto the PDP-11 instruction set. Lots of people got used to using octal, and it carried forward into hex computers.The current syntax for octals is horrible anyway. Why don't you make it into 0o123? -i.
Aug 06 2003
"Ilya Minkov" <midiclub 8ung.at> wrote in message news:bgrkfk$1db9$1 digitaldaemon.com...Walter wrote:yearsThat exact syntax has been supported by Digital Mars C and C++ for 20That is true!now. It's even supported as a printf format. To my knowledge, nobody has ever used it.Because it's not *standard*, man! It's being avoided for portability! Why do you think people use C++? Because it's *standard*. Whatever makes it into D, shall become standard within D. And thus gradually accepted.stickThe truth is, it's easier to deal with bit patterns in hex.Not always.Quick, what is the value of 0b110010000001000? If you're like me, youcreatinga penpoint on the screen and count the 0's. So much easier to deal with 0x6408. The only time I found binary notation useful was when I wasKind of silly looking, maybe whitespace something like string literals: 0b 11111000 00011111 I can't think of anything off the top of my head that would break with this.data for a bitmapped cursor <g>.Argh. You must allow for an underscore in numbers. It shall also do readability of integers and floating-point numbers a lot of good. 0b_11111000_00011111BTW, does this bitmask ring the bell? Well, things like that are not at all rare, and i don't want to need a bin-hex table at hand all the time!gotI don't see octal used so much anymore, but a lot of legacy code used it because it mapped well onto the PDP-11 instruction set. Lots of peopleFor my opinion on binary literals: I've learned to live with using hex so it won't really bother me either way, but it does seem like a good idea to add.used to using octal, and it carried forward into hex computers.The current syntax for octals is horrible anyway. Why don't you make it into 0o123? -i.
Aug 06 2003
Argh. You must allow for an underscore in numbers. It shall also do readability of integers and floating-point numbers a lot of good. 0b_11111000_00011111What an amazing and obvious idea. I can't believe no-one's thought of it before. Please can we allow this syntax for all integer literals (of whatever base) in D!?
Aug 06 2003
Matthew Wilson wrote:See Ada.Argh. You must allow for an underscore in numbers. It shall also do readability of integers and floating-point numbers a lot of good. 0b_11111000_00011111What an amazing and obvious idea. I can't believe no-one's thought of it before.
Aug 06 2003
"Burton Radons" <loth users.sourceforge.net> wrote in message news:bgs98u$20a6$1 digitaldaemon.com...Matthew Wilson wrote:Ah! :)See Ada.Argh. You must allow for an underscore in numbers. It shall also do readability of integers and floating-point numbers a lot of good. 0b_11111000_00011111What an amazing and obvious idea. I can't believe no-one's thought of it before.
Aug 06 2003
"Ilya Minkov" <midiclub 8ung.at> wrote in message news:bgrkfk$1db9$1 digitaldaemon.com...Walter wrote:yearsThat exact syntax has been supported by Digital Mars C and C++ for 20PC C/C++ compilers had many non-standard compiler unique extensions that were widely used.now. It's even supported as a printf format. To my knowledge, nobody has ever used it.Because it's not *standard*, man! It's being avoided for portability! Why do you think people use C++? Because it's *standard*.gotI don't see octal used so much anymore, but a lot of legacy code used it because it mapped well onto the PDP-11 instruction set. Lots of peopleHaving 01234 mean 668 in C and 1234 in D would be not worth the confusion. I want to avoid changes that would silently and subtly alter the meaning of code that is second nature to many people.used to using octal, and it carried forward into hex computers.The current syntax for octals is horrible anyway. Why don't you make it into 0o123?
Aug 06 2003
Walter wrote:PC C/C++ compilers had many non-standard compiler unique extensions that were widely used.If you leave them no choice...Having 01234 mean 668 in C and 1234 in D would be not worth the confusion. I want to avoid changes that would silently and subtly alter the meaning of code that is second nature to many people.Then why don't you simply forbid numbers which start with a zero? After all, it doesn't have to be silent... -i.
Aug 07 2003
"Ilya Minkov" <midiclub 8ung.at> ha scritto nel messaggio news:bgrkfk$1db9$1 digitaldaemon.com...Argh. You must allow for an underscore in numbers. It shall also do readability of integers and floating-point numbers a lot of good. 0b_11111000_00011111This one *rocks*! Ric
Aug 25 2003
"Walter" <walter digitalmars.com> wrote in message news:bgrfj5$18er$1 digitaldaemon.com..."Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bgrch4$157i$1 digitaldaemon.com...yearsSeconded. Why not 0b01010101? SeanThat exact syntax has been supported by Digital Mars C and C++ for 20now. It's even supported as a printf format. To my knowledge, nobody has ever used it. The truth is, it's easier to deal with bit patterns in hex. Quick, what is the value of 0b110010000001000? If you're like me, yousticka penpoint on the screen and count the 0's. So much easier to deal with 0x6408. The only time I found binary notation useful was when I wascreatingdata for a bitmapped cursor <g>. I don't see octal used so much anymore, but a lot of legacy code used it because it mapped well onto the PDP-11 instruction set. Lots of people got used to using octal, and it carried forward into hex computers.the amount of times I've written 0x0..0xF out as 0b0000 .. 0b1111 on a piece of paper next to me so I could write bit masks or bit fields values out in hex I can not count. I think most C/Java programmers would understand what 0b0010 was and as pointed out its not standard so ppl would not tend to use it. I've worked on C project where // comments where banned even though we used gcc and mcvc++ both support // in C. octal: before you scrap it, think of unix programmers, I believe that file permisions on unix are octal so some ppl may still want it. what about 0o777 for octal, numbers are 0<letter>(letter|digits) for anything not base10 with x or h for hex, b for binary and o for octal
Aug 07 2003
"Mike Wynn" <mike.wynn l8night.co.uk> wrote in message news:bgu39h$n17$1 digitaldaemon.com...the amount of times I've written 0x0..0xF out as 0b0000 .. 0b1111 on apieceof paper next to me so I could write bit masks or bit fields values out in hex I can notcount. I think if you try it in D right now, it already works <g>.octal: before you scrap it, think of unix programmers, I believe that file permisions on unix are octal so some ppl may still want it. what about 0o777 for octal, numbers are 0<letter>(letter|digits) for anything not base10 with x or hforhex, b for binary and o for octalOctal will stay in, and I'll leave it in the C syntax. For those that still want octal, I think they'll want the C syntax they're used to for it.
Aug 07 2003
I would use it. Consider converting a ARGB1555 pixel to ARGB4444 format: (yes, we actually have to do this:) return ((pixel & 0b_1_00000_00000_00000) >> 3) * 0b1111 | ((pixel & 0b_0_11110_00000_00000) >> 3) | ((pixel & 0b_0_00000_11110_00000) >> 2) | ((pixel & 0b_0_00000_00000_11110) >> 1); It gets worse. There are all kinds of pixel formats. Change those numbers above to hex and you really lose the sense of what's going on. We have to resort to writing the values twice, once as hex and once in a comment as binary "documentation". Don't get me wrong: I know hex. I use hex. I love hex. Hex isn't always the right tool, though. The brain takes time and effort to convert hex to binary. If you just write in binary, you see the patterns immediately. Which is more obvious what is going on? 0xAA or 0b10101010 ? When what you are manipulating *is* bits or bit patterns, hex adds a layer of obfuscation. It's not so bad when the fields are aligned well, but when they're not, it can be confusing; deceiving even. Actually these days, this kind of code is usually found only in tools, not in the main game so much anymore. The main game has support hardware to do most of the pixel pushing, and integer SIMD to do what the GPU hardware can't do, fast. The main cpu is not where you want to be doing this kind of stuff. Sean "Walter" <walter digitalmars.com> wrote in message news:bgrfj5$18er$1 digitaldaemon.com..."Sean L. Palmer" <palmer.sean verizon.net> wrote in message news:bgrch4$157i$1 digitaldaemon.com...news:bgr5h8$u9m$1 digitaldaemon.com...Seconded. Why not 0b01010101? Sean "QUS" <qus go2.pl> wrote in messagealwaysAllright - octals are pretty useless (or aren't they?), but I wasyearsbinarymissing binary literals from C++. Would it break anything if we hadThat exact syntax has been supported by Digital Mars C and C++ for 20literals in D? Sometimes it saves a lot of time!now. It's even supported as a printf format. To my knowledge, nobody has ever used it. The truth is, it's easier to deal with bit patterns in hex. Quick, what is the value of 0b110010000001000? If you're like me, yousticka penpoint on the screen and count the 0's. So much easier to deal with 0x6408. The only time I found binary notation useful was when I wascreatingdata for a bitmapped cursor <g>. I don't see octal used so much anymore, but a lot of legacy code used it because it mapped well onto the PDP-11 instruction set. Lots of people got used to using octal, and it carried forward into hex computers.
Aug 08 2003
Ohh yes. That's a spiffy idea! "QUS" <qus go2.pl> wrote in message news:bgr5h8$u9m$1 digitaldaemon.com...Allright - octals are pretty useless (or aren't they?), but I was always missing binary literals from C++. Would it break anything if we had binary literals in D? Sometimes it saves a lot of time!
Aug 06 2003