Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8957399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:58:52+00:00 2026-06-15T14:58:52+00:00

I work with registers a bit, and data sheets that turn everything into bit

  • 0

I work with registers a bit, and data sheets that turn everything into bit indices. Luckily, I’m using GCC, which has the binary literal extension syntax so that i can do things like

register |= 0b01000010;

The other option is of course to just use hexadecimal format

register |= 0x42;

Despite having worked with hexadecimal numbers a bit over time, I still find binary format better for this kind of bit banging. I still decompose the 4 and 2 nibbles into their 0100 and 0010 patterns. So I think the binary format visualizes better. The problem with the binary format though, is that it’s hard to find the boundaries. Using hexadecimal format, the nibbles separate nicely and so you can "index" bits safer sometimes. In other words, in the top I have to worry I didn’t add or omit an extra 0 and end up with bit 7 on instead of 6.

Has a technique/trick been developed to have their cake and eat it too? When you have two string constants adjacent in C

"Hello " "World"

The compiler is smart enough to just mash them together into one literal. It would be nice if there was a way to do something similar with these binary numbers, e.g.,

0b0100 0010

I could do something weird with macros, perhaps

#define _(a, b) (((a) << 4) | (b))

and then be able to do

_(0b0100,0b0010)

but that’s honestly worse, and limited to a pair of nibbles. Is there something clever and nice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T14:58:54+00:00Added an answer on June 15, 2026 at 2:58 pm

    In C, you’re limited to specifying integer constants in decimal, octal, and hexadecimal. Or combine groups of shifted constants (per H2CO3’s comment below your question). If it’s important enough to you, you could specify your contants as quoted string constants and call a function (of your own writing) to convert that & return its integer value. Anywhere you want to specify such a constant, just call your function in its place… int i = b("0100 1101 0011 1100"); ….Or use C++…. See Binary literals? and Can I use a binary literal in C or C++?

    If you go with writing your own string constant converter, you can make it ignore non-[0,1] digits, so you can group the bits in any fashion depending on what you’re specifying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some old code written in C for 16-bit using Borland C++ that
I want to register a script with wordpress that will work on the backend.
An application I have recently started work on has to register two dll's, because
I have routes like: /, /login, /register, etc that work fine in dev environment.
work on SQL Server 2000. want to Automated Email Notifications using SQL Server Job
Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit
I need to write a program in 8086 Assembly that receives data from the
Okay first up I am using: DirectX 10 C++ Okay this is a bit
I'm having a bit of trouble getting a SQL query to work. Some background
I am doing some work with a 3rd party supplier who provide data via

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.