August 07, 2003 Re: Quick and easy request: binary literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Burton Radons | "Burton Radons" <loth@users.sourceforge.net> wrote in message news:bgs98u$20a6$1@digitaldaemon.com... > Matthew Wilson wrote: > >>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 > > > > > > What an amazing and obvious idea. I can't believe no-one's thought of it before. > > See Ada. > Ah! :) |
August 07, 2003 Re: Quick and easy request: binary literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | "Ilya Minkov" <midiclub@8ung.at> wrote in message news:bgrkfk$1db9$1@digitaldaemon.com... > 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*. PC C/C++ compilers had many non-standard compiler unique extensions that were widely used. > > 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? 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. |
August 07, 2003 Re: Quick and easy request: binary literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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. |
August 07, 2003 Re: Quick and easy request: binary literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | "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... > > Seconded. > > > > Why not 0b01010101? > > > > Sean > > > 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. 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. > 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 |
August 08, 2003 Re: Quick and easy request: binary literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Wynn | "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 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 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 h for > hex, b for binary and o for octal Octal 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. |
August 08, 2003 Re: Quick and easy request: binary literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | 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... > > 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! > > 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. 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. |
August 25, 2003 Re: Quick and easy request: binary literals | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | "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_00011111 This one *rocks*! Ric |
Copyright © 1999-2021 by the D Language Foundation