Shop OBEX P1 Docs P2 Docs Learn Events
Converting byte contents to one number? — Parallax Forums

Converting byte contents to one number?

Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
edited 2008-03-25 04:21 in Propeller 1
Question:


I have byte[noparse][[/noparse]0], byte1, and byte2....

byte[noparse][[/noparse]0] contains character 49 (a 1)
byte1 contains character 50 (a 2)
byte2 contains character 51 (a 3)




How do I combine these to create a singe number (123) in byte3?

for some reason the code command won't process this example.


Thanks
OBC

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
New to the Propeller?

Getting started with the Protoboard? - Propeller Cookbook 1.4
Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
Got an SD card? - PropDOS
A Living Propeller FAQ - The Propeller Wiki
(Got the Knowledge? Got a Moment? Add something today!)

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-03-25 01:36
    byte3 := (byte0-"0")*100 + (byte1-"0")*10 + (byte2-"0")

    You can also do this in a loop with
    byteVal[noparse][[/noparse] 3 ] := 0
    repeat i from 0 to 2
       byteVal[noparse][[/noparse] 3 ] := byteVal[noparse][[/noparse] 3 ]*10 + byteVal[noparse][[/noparse] i ] - "0"
    
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-03-25 04:21
    Thanks Mike, that loop did the trick.. Incorporated into Spudview for reading the image size.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with the Protoboard? - Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card? - PropDOS
    A Living Propeller FAQ - The Propeller Wiki
    (Got the Knowledge? Got a Moment? Add something today!)

Sign In or Register to comment.