Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Ads

Discussion Groups

Discussion Groups | Comp.Arch.Embedded | Simple C question...entering binary

There are 45 messages in this thread.

You are currently looking at messages 30 to 40.

Re: Simple C question...entering binary - CBFalconer - 16:40 29-01-08

Eric Smith wrote:
> CBFalconer <c...@yahoo.com> writes:
> 
>>>>> to get all 1s, better is ~0
>>>> How is that better?
>>> should work on 1s-complement machines.
> 
>> So does "unsigned int u = -1;".
> 
> On a 1's complement machine, that will result in the variable ul
> having al bits set other than the least signficant bit, since that
> is the one's complement representation of -1.

Which is what was wanted.

-- 
 [mail]: Chuck F (cbfalconer at maineline dot net) 
 [page]: <http://cbfalconer.home.att.net>;
            Try the download section.



-- 
Posted via a free Usenet account from http://www.teranews.com




Re: Simple C question...entering binary - Mark Piffer - 18:48 29-01-08

On 19 Jan., 17:41, Albert van der Horst <alb...@spenarnc.xs4all.nl>
wrote:
> In article <47914AAB.E10DF...@yahoo.com>,
>
> >You can enter the value in hex, octal, or decimal.  For example:
>
> >          unsigned int x;
> >          ....
> >          x = 0xffff;
> >/* or */  x = 0177777;
> >/* or */  x = 65535U;
> >/* or */  x = 0170000 + 0xf00 + 255U;
>
> And the most convenient of all
>            x = -1;
>
> (For those not in the know, the definition of unsigned
> explicitly makes this works. There may be an additional
> advantage that it ports over to 64 bits more easily.)
>
> And of course:
>
>     x = ~0;

I would rather use ~0u. ~0 smells of undefined behaviour although most
compilers will do it right.

>
>
>
> --
> Albert van der Horst, UTRECHT,THE NETHERLANDS
> Economic growth -- like all pyramid schemes -- ultimately falters.
> albert@spe&ar&c.xs4all.nl &=nhttp://home.hccnet.nl/a.w.m.van.der.horst

regards,
Mark

Re: Simple C question...entering binary - Eric Smith - 19:22 29-01-08

msg <m...@_cybertheque.org_> writes:
> I don't have my old manuals handy; was the Unisys 10000 series
> 1's complement?

I don't know about any 10000 series, but the 1100 series was.

Re: Simple C question...entering binary - msg - 21:42 29-01-08

Eric Smith wrote:

> msg <m...@_cybertheque.org_> writes:
> 
>>I don't have my old manuals handy; was the Unisys 10000 series
>>1's complement?
> 
> 
> I don't know about any 10000 series, but the 1100 series was.

My apologies; I transposed NCR and Unisys in my mind. The
NCR 10000 Series was a successor to early NCR architectures
contemporary with the Univac 1107.

Michael

Re: Simple C question...entering binary - CodeDog - 12:51 14-07-08

I now submit to the public domain, free of charge...

enum {
b0000,
b0001,
b0010,
b0011,
b0100,
b0101,
b0110,
b0111,
b1000,
b1001,
b1010,
b1011,
b1100,
b1101,
b1110,
b1111,
};

lol




Re: Simple C question...entering binary - Walter Banks - 15:45 14-07-08

Most of the embedded people did something similar

#define b00000000  0
#define b00000001  1
. . .

before 0b....

was implemented as an extension in most compilers including ours.

w..


CodeDog wrote:

> I now submit to the public domain, free of charge...
>
> enum {
> b0000,
> b0001,
> b0010,
> b0011,
> b0100,
> b0101,
> b0110,
> b0111,
> b1000,
> b1001,
> b1010,
> b1011,
> b1100,
> b1101,
> b1110,
> b1111,
> };
>
> lol


Re: Simple C question...entering binary - David Brown - 16:56 14-07-08

Walter Banks wrote:
> Most of the embedded people did something similar
> 
> #define b00000000  0
> #define b00000001  1
> . . .
> 
> before 0b....
> 
> was implemented as an extension in most compilers including ours.
> 

I'd guess that "most of the embedded people" used hex or some sort of (1 
<< n) notation.  But it's nice having 0b numbers available - is it 
common on other compilers yet?  (gcc has it from 4.3 onwards, with 
avr-gcc supporting it from much earlier.)

Re: Simple C question...entering binary - Walter Banks - 11:06 15-07-08


David Brown wrote:

> Walter Banks wrote:
> > Most of the embedded people did something similar
> >
> > #define b00000000  0
> > #define b00000001  1
> > . . .
> >
> > before 0b....
> >
> > was implemented as an extension in most compilers including ours.
> >
>
> I'd guess that "most of the embedded people" used hex or some sort of (1
> << n) notation.  But it's nice having 0b numbers available - is it
> common on other compilers yet?  (gcc has it from 4.3 onwards, with
> avr-gcc supporting it from much earlier.)

Many embedded compilers now to support 0b.... I don't have a list of who
does support the binary syntax.  I raised the issue at  WG-14 one time and
support was divided between hosted vs non-hosted experience. The
hosted folks suggested 0x... was all that was needed.

w..





Re: Simple C question...entering binary - Robert Adsett - 20:31 15-07-08

In article <4...@bytecraft.com>, Walter Banks says...
> 
> 
> David Brown wrote:
> 
> > Walter Banks wrote:
> > > Most of the embedded people did something similar
> > >
> > > #define b00000000  0
> > > #define b00000001  1
> > > . . .
> > >
> > > before 0b....
> > >
> > > was implemented as an extension in most compilers including ours.
> > >
> >
> > I'd guess that "most of the embedded people" used hex or some sort of (1
> > << n) notation.  But it's nice having 0b numbers available - is it
> > common on other compilers yet?  (gcc has it from 4.3 onwards, with
> > avr-gcc supporting it from much earlier.)
> 
> Many embedded compilers now to support 0b.... I don't have a list of who
> does support the binary syntax.  I raised the issue at  WG-14 one time and
> support was divided between hosted vs non-hosted experience. The
> hosted folks suggested 0x... was all that was needed.

I tend to agree with them.  I find reading hex (or x << y) a lot easier 
than counting bits in a binary number.

Robert
** Posted from http://www.teranews.com **

Re: Simple C question...entering binary - Niklas Holsti - 02:46 16-07-08

Robert Adsett wrote:
> In article <4...@bytecraft.com>, Walter Banks says...
> 
>>
>>David Brown wrote:
>>
>>
>>>Walter Banks wrote:
>>>
>>>>Most of the embedded people did something similar
>>>>
>>>>#define b00000000  0
>>>>#define b00000001  1
>>>>. . .
>>>>
>>>>before 0b....
>>>>
>>>>was implemented as an extension in most compilers including ours.
>>>>
>>>
>>>I'd guess that "most of the embedded people" used hex or some sort of (1
>>><< n) notation.  But it's nice having 0b numbers available - is it
>>>common on other compilers yet?  (gcc has it from 4.3 onwards, with
>>>avr-gcc supporting it from much earlier.)
>>
>>Many embedded compilers now to support 0b.... I don't have a list of who
>>does support the binary syntax.  I raised the issue at  WG-14 one time and
>>support was divided between hosted vs non-hosted experience. The
>>hosted folks suggested 0x... was all that was needed.
> 
> 
> I tend to agree with them.  I find reading hex (or x << y) a lot easier 
> than counting bits in a binary number.

Reading binary numbers is easier when the language lets you 
separate the binary digits into logical groups, for example with 
underscores as in the Ada form:

    2#10_10110_001000_11111_1_0000000010000#

which is the 32-bit encoding of the SPARC instruction "addx 
r31,16,r22", grouped according to the logical fields of the 
encoding. The "_" has no numerical meaning, so the above is the 
same as:

    2#10101100010001111110000000010000#

Perhaps the C compilers that support the 0b... notation should 
allow some form of grouping like this.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .

previous | 1 | 2 | 3 | 4 | 5 | next