DSPRelated.com
Forums

Simple binary number notation question

Started by Rick Lyons December 1, 2004

Hi Guys,

I have a silly little question:

I've periodically come across the "0xqqqq"
notation for a 16-bit binary word.
For example: 
  
    0x7b20 

I don't know what is the meaning of the 
"0x" characters in the above notation.

I searched around the Internet looking for 
an answer to my question, but couldn't find 
anything useful.

Can someone tell me what is the purpose of 
the "0x" characters in the notation "0x7b20"?
(I know the "7b20" characters mean four 
hex numbers, but why bother to include 
the "0x" characters?)

Thanks,
[-Rick-]

Derives from the C language.

Any number starting with a leading zero is Octal, any
number starting with 1- 9 is decimal, 0x is the Hex prefix.

"Rick Lyons" <r.lyons@_BOGUS_ieee.org> wrote in message
news:41adb3ed.69921125@news.sf.sbcglobal.net...
> I've periodically come across the "0xqqqq" > notation for a 16-bit binary word. > For example: > 0x7b20 > > I don't know what is the meaning of the > "0x" characters in the above notation. > I searched around the Internet looking for > an answer to my question, but couldn't find > anything useful.
Rick,

"0x" simply means that this is a hexadecimal number. Obviously you can 
guess that from the "b" in your example, but for other numbers you 
cannot so you need to make sure the reader refers to the same basis.
-- 
Stephan M. Bernsee
http://www.dspdimension.com

"Rick Lyons" <r.lyons@_BOGUS_ieee.org> wrote in message
news:41adb3ed.69921125@news.sf.sbcglobal.net...
> > > Hi Guys, > > I have a silly little question: > > I've periodically come across the "0xqqqq" > notation for a 16-bit binary word. > For example: > > 0x7b20 > > I don't know what is the meaning of the > "0x" characters in the above notation. > > I searched around the Internet looking for > an answer to my question, but couldn't find > anything useful. > > Can someone tell me what is the purpose of > the "0x" characters in the notation "0x7b20"? > (I know the "7b20" characters mean four > hex numbers, but why bother to include > the "0x" characters?)
Shows you the word size explicitly.
r.lyons@_BOGUS_ieee.org (Rick Lyons) wrote in news:41adb3ed.69921125
@news.sf.sbcglobal.net:

> > > Hi Guys, > > I have a silly little question: > > I've periodically come across the "0xqqqq" > notation for a 16-bit binary word. > For example: > > 0x7b20 > > I don't know what is the meaning of the > "0x" characters in the above notation. > > I searched around the Internet looking for > an answer to my question, but couldn't find > anything useful. > > Can someone tell me what is the purpose of > the "0x" characters in the notation "0x7b20"? > (I know the "7b20" characters mean four > hex numbers, but why bother to include > the "0x" characters?) > > Thanks, > [-Rick-] > >
I don't have any idea who came up with 0x but its purpose is clear enough. Its been with us for some time. I found it in my first edition, Kernighan & Ritchie C "White" Book. This is the O&S of C programming. If I write 7b20, I might assume hexadecimal, but what about 1234? 1234 (decimal) is certainly not 0x1234 -- Al Clark Danville Signal Processing, Inc. -------------------------------------------------------------------- Purveyors of Fine DSP Hardware and other Cool Stuff Available at http://www.danvillesignal.com
"Stephen Maudsley" <news2@sjmaudsley.fsnet.co.uk> writes:

> "Rick Lyons" <r.lyons@_BOGUS_ieee.org> wrote in message > news:41adb3ed.69921125@news.sf.sbcglobal.net... > > > > > > Hi Guys, > > > > I have a silly little question: > > > > I've periodically come across the "0xqqqq" > > notation for a 16-bit binary word. > > For example: > > > > 0x7b20 > > > > I don't know what is the meaning of the > > "0x" characters in the above notation. > > > > I searched around the Internet looking for > > an answer to my question, but couldn't find > > anything useful. > > > > Can someone tell me what is the purpose of > > the "0x" characters in the notation "0x7b20"? > > (I know the "7b20" characters mean four > > hex numbers, but why bother to include > > the "0x" characters?) > > Shows you the word size explicitly.
Not true. It explicitly denotes the number base. 0x7b20 can be any size from 16 bits on up, depending on the compiler and the platform. For example, on a TMS320C54x I can write int x; long y; x = 0x7b20; y = 0x7b20; printf("this is a 16-bit number: %d", x); printf("this is a 32-bit number: %ld", x); -- Randy Yates Sony Ericsson Mobile Communications Research Triangle Park, NC, USA randy.yates@sonyericsson.com, 919-472-1124
r.lyons@_BOGUS_ieee.org (Rick Lyons) writes:

> Hi Guys, > > I have a silly little question: > > I've periodically come across the "0xqqqq" > notation for a 16-bit binary word. > For example: > > 0x7b20 > > I don't know what is the meaning of the > "0x" characters in the above notation.
Hi Rick, It is the "C" way to specify that an integer constant is base 16. Prefixing an integer constant with "0" specifies the constant is base 8. I think this also works for some assemblers. There are also C-standard ways to specify that an integer constant is a long (using suffix "L") and unsigned (using suffix "U"). A suffix of "f" denotes the (not-necessarily-integer-) constant is a float. --Randy -- Randy Yates Sony Ericsson Mobile Communications Research Triangle Park, NC, USA randy.yates@sonyericsson.com, 919-472-1124
Randy Yates <randy.yates@sonyericsson.com> writes:
> [...] > int x; > long y; > > x = 0x7b20; > y = 0x7b20; > printf("this is a 16-bit number: %d", x); > printf("this is a 32-bit number: %ld", x);
--------------------------------------------^ should be "y". --perils-of-cut-and-pastely-yours, Randy -- Randy Yates Sony Ericsson Mobile Communications Research Triangle Park, NC, USA randy.yates@sonyericsson.com, 919-472-1124

Rick Lyons wrote:
> Hi Guys, > > I have a silly little question: > > I've periodically come across the "0xqqqq" > notation for a 16-bit binary word. > For example: > > 0x7b20 > > I don't know what is the meaning of the > "0x" characters in the above notation. > > I searched around the Internet looking for > an answer to my question, but couldn't find > anything useful. > > Can someone tell me what is the purpose of > the "0x" characters in the notation "0x7b20"? > (I know the "7b20" characters mean four > hex numbers, but why bother to include > the "0x" characters?)
The leading "0" is to tell the compiler (etc.) that this is the start of a number. The "x" then says that this is a strange number because it is base 16 (hexadecimal for prudes of yesteryear rather than sexadecimal as the linguists would have it).
> Thanks, > [-Rick-] >
"Rick Lyons" <r.lyons@_BOGUS_ieee.org> wrote in message
news:41adb3ed.69921125@news.sf.sbcglobal.net...
> I've periodically come across the "0xqqqq" > notation for a 16-bit binary word. > For example: > > 0x7b20 > > I don't know what is the meaning of the > "0x" characters in the above notation.
This is the C language's (and a number of other languages') notation for hexadecimal literals to avoid possible confusion in the case of a hexadecimal number that only includes numeric decimal digits. In some assemblers, the notation is 0qqqqh, or just qqqqh if the first digit happens to be a decimal digit. Other assemblers have used #qqqq, and I'm sure there's plenty of other notations. Regards, Howard