Why Do I Have To Type 0b Before The Binary Number? - Codecademy

Skip to ContentProfile image of chipBlaster33731Submitted by chipBlaster33731about 11 yearswhy do I have to type 0b before the binary number?

Hi!

why do I have to type 0b before the binary number?

I have noticed that python still reads it as binary without 0b just that I get completely different results with or without 0b.

Answer 52856e24548c359138000f00

1 vote

Permalink

0b is a way that python uses to tell what the base number is:

print bin(10) # binary use 0b prefix and are base 2 print oct(10) # octal use 0 prefix and are base 8 print hex(10) # hexadecimal use 0x and are base 16 print int("A",16)

by having these prefixes it allows for not only humans to see the difference but also alow for python to use the right base.

Foreach position in a binary number it can hold a ‘0’ or a ‘1’ = 2 Foreach position in a Hex number it can hold 0-9 and A-F = 16 hence its base

Profile image of designNinja91264Submitted by designNinja91264about 11 years

2 comments

Profile image of chipBlaster33731Submitted by chipBlaster33731about 11 years

I see, what comes “first” letters or numbers? And what is the prefix to use hex?

Thank you for your answer!

Profile image of designNinja91264Submitted by designNinja91264about 11 years

The prefix for hex is 0x and numbers come first

Popular free courses

  • Free course

    Learn SQL

    In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Checker DenseBeginner Friendly4 Lessons
  • Free course

    Learn JavaScript

    Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Checker DenseBeginner Friendly11 Lessons
  • Free course

    Learn HTML

    Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Checker DenseBeginner Friendly6 Lessons
Explore full catalog

Từ khóa » C 0b 0x