Char representation in byte

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Krikelis

    #1

    Char representation in byte

    Hi,

    I have a problem converting chars that are represented in
    more then 7F(in hex). I need to convert char to byte.
    When I cast chars into bytes it is no problem when chars
    are <= 7F(in hex), however when I do same thing to for
    example char (%divided by infinity which is 89(in hex) it
    gives me error out of bound. because it somehow converts
    it into the decimal 8240 which requires 2 bytes.

    Please, any help would be appresiated.

    Pete.
  • Jon Skeet [C# MVP]

    #2
    Re: Char representation in byte

    Peter Krikelis <anonymous@disc ussions.microso ft.com> wrote:[color=blue]
    > I have a problem converting chars that are represented in
    > more then 7F(in hex). I need to convert char to byte.[/color]

    That's going to be tricky given that chars in .NET are 16 bit entities
    and bytes are only 8 bit entities.
    [color=blue]
    > When I cast chars into bytes it is no problem when chars
    > are <= 7F(in hex), however when I do same thing to for
    > example char (%divided by infinity which is 89(in hex) it
    > gives me error out of bound. because it somehow converts
    > it into the decimal 8240 which requires 2 bytes.[/color]

    I think you actually mean Unicode 8240, (0x2030). In what way is that
    89 in hex?

    (It's not actually % divided by infinity, it's % with an extra ring at
    the bottom, but I don't think it can be coincidence that it sounds so
    like what you're talking about.)

    See http://www.pobox.com/~skeet/csharp/unicode.html for more info.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Jeroen Smits

      #3
      Re: Char representation in byte

      > (It's not actually % divided by infinity, it's % with an extra ring at[color=blue]
      > the bottom, but I don't think it can be coincidence that it sounds so
      > like what you're talking about.)[/color]

      It's called the per-mille sign.

      % - per cent i.e. per hundrend
      %o - per mille => per thousand

      0.1 percent = 1 permille


      Comment

      Working...